MySQL Forums
Forum List  »  PHP

MySQLi fetch corrupting bound variables
Posted by: Stuart Milne
Date: August 25, 2011 03:43AM

Hi there

Getting a weird issue with MySQLi fetch when using bound variables.

First of all here is some example code.

<?php

$pID = 0;
$recordID = 0;

if ($stmt = $dbObj->prepare('SELECT `id`, name FROM MYTABLE WHERE id = ?)
{

if ($stmt->bind_param('i', $pID))
{
if ($stmt->bind_result($recordID, $name)
{
if ($stmt->execute())
{
$stmt->fetch();
}
}
}

}

Now i initialize the $recordID variable to 0;

The SELECT statement then does a SELECT where id = 0; In my table there is no record with the id of 0;

Also notice that in my bind_result i am binding the the result into the $recordID variable.

Now this is where it gets weird for me. On some versions of PHP and MYSQl the $recordID variable is still set to 0 but on other versions of PHP mYSQL the $recordID seems to be overwritten and set to NULL from the fetch.

Any ideas as to why these differences are occurring.

Regards
Stu

?>

Options: ReplyQuote


Subject
Written By
Posted
MySQLi fetch corrupting bound variables
August 25, 2011 03:43AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.