Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC database with memo field causes errors

Status
Not open for further replies.

scriggs

IS-IT--Management
Joined
Jun 1, 2004
Messages
286
Location
GB
I loop through an ODBC datasource and deal with each field in turn. If the field type is MEMO then PHP returns an error. Is there a way to detect the field type and skip the field and then avoid the error?

Error:
Warning: odbc_result(): SQL error: [Microsoft][ODBC Driver Manager] Invalid cursor state, SQL state 24000 in SQLGetData in E:\NewIntranet\scripts\files.inc.php on line

Code:
Code:
$query = "SELECT * FROM qryclientsData WHERE ClientKey like '" . $_POST['custname'] . "' ORDER BY ClientKey ;";

if(!($odbc_db = odbc_connect($odbc_dsn, $odbc_userid, $odbc_password)))
	die ("Could not connect ot ODBC data source $odbc_dsn");
  
if(!($odbc_rs = odbc_do($odbc_db, $query)))
	die("Error executing query $query");
  
$num_cols = odbc_num_fields($odbc_rs);
if($num_cols < 1) die("Query returned an empty set");

    for( $i = 0; $i <= $num; $i++ )
    {
       odbc_fetch_row( $odbc_rs );

    //use column headings

     for($a=1;$a<=$num_cols;$a++)
     {
    //  echo odbc_field_name($odbc_rs, $a);
    $fieldname = odbc_field_name($odbc_rs, $a);
    $wordfieldname = '[' . $fieldname . ']';
    $results = odbc_result( $odbc_rs, $fieldname);
 
I have made a work around myself and thought I would post it for reference - this queries the field type and skips if memo:

Code:
    $fieldtype = odbc_field_type($odbc_rs, $a);
    //check if field is a MEMO and skip
    if ($fieldtype != "LONGCHAR") {
        do something;
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top