Re: MYSQLi fetch corrupting bound variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Shouldn't you "execute" the query first, and then "bind_result" ??

In the php doc (http://jp2.php.net/manual/fr/mysqli-stmt.bind-result.php) the example is done this way...

Hope this helps,

Olivier

Le 25/08/2011 13:04, Stuart Milne a écrit :
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
________________________________
E-MAIL DISCLAIMER
The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. All information provided, including but not limited to, quotations, system specifications and suggestions concerning hardware/software/services configurations are strictly subject to our standard terms and conditions of business, copies of which are available on request.

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--
---------------
Olivier Bietzer


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux