php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32928 php dies trying to ->bind_result(...)
Submitted: 2005-05-03 16:19 UTC Modified: 2005-05-07 08:44 UTC
From: dan at yes dot lt Assigned: georg (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.0.4, 5.0.5-dev OS: winxp
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dan at yes dot lt
New email:
PHP Version: OS:

 

 [2005-05-03 16:19 UTC] dan at yes dot lt
Description:
------------
php dies trying to mysqli_stmt->bind_result(...) with listed queries:

SELECT 1.23 AS test

SELECT NULL AS test

php version 5.0.4, mysql version 5.0.4 beta

Reproduce code:
---------------
$st = $db->prepare("SELECT 1 AS test");
$st->bind_result($x);
$st->fetch();
var_dump($x);

$st = $db->prepare("SELECT 1.23 AS test");
$st->bind_result($x);
$st->fetch();
var_dump($x);

$st = $db->prepare("SELECT NULL AS test");
$st->bind_result($x);
$st->fetch();
echo $st;
var_dump($x);


Expected result:
----------------
int(1)
float(1.23)
NULL


Actual result:
--------------
int(1)
...FATAL ERROR WITH NO OUTPUT...
...FATAL ERROR WITH NO OUTPUT...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-04 09:58 UTC] georg@php.net
Looks like repreparing a statement without closing it 
makes some problems -> assigned (tested against 
5.0.5-beta) 
 
The script itself works as expected - fetching a row 
without executing statement before returns an error. 
 [2005-05-05 15:41 UTC] georg@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Prepared statements return unbuffered resultsets by default,
therefore you have to retrieve all data or close the resultset before any command to the server.

The last statement doesn't work, cause MYSQL_TYPE_NULL is unsupported (filed as bug #32956).
 [2005-05-05 15:47 UTC] dan at yes dot lt
this is not NULL or unbuffered resultset only...
try this:

Reproduce code:
---------------
$st = $db->prepare("SELECT 1.23 AS test");
$st->bind_result($x);
$st->fetch();
var_dump($x);

Expected result:
----------------
float(1.23)

Actual result:
--------------
...FATAL ERROR WITH NO OUTPUT...

or maybe floats are also unsupported ?..
 [2005-05-06 03:14 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip


 [2005-05-06 08:44 UTC] dan at yes dot lt
php also dies with latest snapshot
 [2005-05-06 15:43 UTC] georg@php.net
Doesn't crash here (tested against PHP-5.0.5-dev and PHP-5.1.0-dev) and returns NULL as expected.

Please reread the documentation on how to work with prepared statements. It makes no sense to fetch a value from a prepared statement without executing it before.


 [2005-05-06 16:48 UTC] dan at yes dot lt
Still crashes for me with latest 5.0.5-dev... Just forgot to write ->execute() in sample.
MySQL version 5.0.4 - may be this is important.

// This works
$db = new mysqli(...);
$st = $db->prepare("SELECT 1 AS test");
$st->execute();
$st->bind_result($x);
$st->fetch();
var_dump($x);

// This crashes
$db = new mysqli(...);
$st = $db->prepare("SELECT 1.23 AS test");
$st->execute();
$st->bind_result($x);
$st->fetch();
var_dump($x);

// This crashes too
$db = new mysqli(...);
$st = $db->prepare("SELECT NULL AS test");
$st->execute();
$st->bind_result($x);
$st->fetch();
var_dump($x);
 [2005-05-07 08:44 UTC] andrey@php.net
Your example is broken - you don't call execute() on the prepared statement object. However, this reveals another problem - whenever a unbuffered query is used (mysqli_stmt_store_result not called) the wire has to be cleaned before the next prepare. One call to fetch() does not help. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC