Page 1 of 1

ODBC problems :( num_rows and another

Posted: Thu Jun 22, 2006 4:56 pm
by nickk
I have the following code

Code: Select all

//Allready conected to database
$sql = "select * from users where user_id='4'";
$result = odbc_exec($dblink, $sql);
$row = odbc_fetch_array($result);
echo $row['name'];
//The above works properly with no problems what so ever

$sql = "select * from products where product_id='3'";
$result = odbc_exec($dblink, $sql); //Here I get the error
I KEEP getting some cursor error (Im sorry I dont remember the exact error and I cant check right now). This is VERY frustrating and I need to solve it. Any suggestions.

Secondly, as it states on the php.net website, odbc_num_rows works very poorly in many cases including mine, so what I did is simply use something along these lines

Code: Select all

$counter = 0;
while(odbc_fetch_row($result))
{
    $counter++;
}
echo $counter;
I really dont like this, is there any better way?

Thanks alot in advance

Posted: Thu Jun 22, 2006 5:20 pm
by HCBen
Try calling odbc_free_result() before your next odbc_exec().

See http://us2.php.net/manual/en/function.o ... result.php for more info.

If you're trying to get a record count, it's often best to simply use SQL: "select count(col_name) from table".

Cheers,

- Ben