php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29283 Statement isn't valid anymore warning during executing prepared mysqi queries
Submitted: 2004-07-20 20:15 UTC Modified: 2004-09-02 06:53 UTC
Votes:8
Avg. Score:4.8 ± 0.7
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:0 (0.0%)
From: divisor at ad69 dot com Assigned: georg
Status: Closed Package: MySQL related
PHP Version: 5.0.0 OS: FreeBSD 4.10
Private report: No CVE-ID:
 [2004-07-20 20:15 UTC] divisor at ad69 dot com
Description:
------------
The problem is in CLI as well as in apache module

I have mysql 4.3.1 and php 5.0.0 installed, use mysqli interface to work with mysql.

In different scripts in different places (mostly random) I get the following error:

1) Warning message: Statement isn't valid anymore
2) Statetment result contains no data

Reproduce code:
---------------
appears in randomly different places, all like this:

($DB is mysqli object)

if ($stmt=$DB->prepare("select something from table where name=?")) {
	$stmt->bind_param('s',$name);
	$stmt->execute();

Expected result:
----------------
The same code worked fine on the second server running FreeBSD 5.2.1 without any problems. The main difference between 2 servers I think that the first one (where bug appears) is a productional server with many requests to apache/php/mysql, the second one is a development server with no usage.

Actual result:
--------------
get Warning: Statement isn't valid anymore message and statetment isn't executed

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-20 20:17 UTC] divisor at ad69 dot com
sorry I've accidently provided wrong mysql version
of course it's mysql 4.1.3 beta
 [2004-07-21 10:03 UTC] georg@php.net
Please provide a short script, where we can see where the 
error occurs. Also try to catch the errormessages via 
->stmt_error/errno properties. 
 [2004-07-21 16:24 UTC] divisor at ad69 dot com
it caused randomly on all statetments, prepare() was ok but execute() failed:

if ($stmt=$DB->prepare("select something from table where name=?")) {
	$stmt->bind_param('s',$name);
	$stmt->execute(); // HERE PHP WRITE WARNING
                          // AND STMT COINTAIN NO DATA

variables stmt->error, stmt->errno are empty

that's strange but after removing lines 182-187 from ext/mysqli/php_mysqli.h:

if (!strcmp((char *)__name, "mysqli_stmt")) {\
                if (!((MYSQL_STMT *)__ptr)->mysql) {\
                        php_error(E_WARNING, "Statement isn't valid anymore");\
                        RETURN_NULL();\
                }\
        }\
} 

it started working without any problems. but of course this 'hack' of php code isn't good ;)
 [2004-07-25 18:33 UTC] dev at edwinchu dot info
Hi,

I have got the same problem. I am using PHP5 release with MySQL4.1.3-beta. 

The code is simple:

$mysqli = new mysqli(); // connected successfully
$stmt = $mysqli->prepare("SOME VALID QUERY");
$stmt->execute(); // No problem here

$mysqli2 = $mysqli;
$mysqli2->query("THE SAME QUERY"); // Still OK
$stmt2 = $mysqli2->prepare("THE SAME QUERY");
$stmt2->execute();

The last line failed and returning "Warning: Statement isn't valid anymore in xxx".
 [2004-08-03 08:48 UTC] alex at avannaproductions dot com
I'll chime in as another voice of reason: this should be 
fixed before 5.0.1. At the moment, prepared statements 
are basically useless, as half the time they give this 
error and fail to return any data. I'm on MacOS X and 
Apache 2, with the same problem.
 [2004-08-20 14:47 UTC] paradox at gmx dot at
i've got the same problem with php 5.0.1 loaded as an apache module - mysql 4.1.3beta, win2k
it seems that the error occurs more often on much used servers. on my dedicated test-server it is approximately one error on 100 statements.
 [2004-09-01 22:18 UTC] corey_gilmore at dpc dot senate dot gov
I'm experiencing the same issue as well with Apache 1.3.31 and 2.0.50 on XP SP2 and XP SP1 with PHP 5.0, 5.01 and 5.0-DEV from php5-win32-200408312230.zip.  MySQL 4.1a, 4.1.2, 4.1.3 and now 4.1.4.  It occurs in a page where I select a large amount of data from one table, process it, and insert it into multiple tables.  There are 287 rows returned from the first select, and then 400-500 rows inserted.

Line 644 begins with 'if( !$stmt->execute() ) {'

Warning: Statement isn't valid anymore in ...\import\contact.class.inc.php on line 644
Error inserting email (#0): INSERT INTO email (EmailType, Email, ContactID) VALUES (?, ?, ?);

$sql = "INSERT INTO {$kTABLE_PREFIX}email (EmailType, Email, ContactID) VALUES (?, ?, ?)";
if( !$stmt = $db->prepare($sql) ) { // prepare it
	printf("Error with %s:<br>%s<br>",$sql, $db->error );
}
if( !$stmt->bind_param("ssi", $addr->EmailType, $addr->Email, $ContactID ) ) {
	printf("Error (#%d): %s;<br>%s<br>%s : %s : %s<br>", $stmt->errno, $sql, $stmt->error, $addr->EmailType, $addr->Email, $ContactID );
}
 
if( !$stmt->execute() ) {
	printf("Error inserting email (#%d): %s;<br>%s<br>%s : %s : %i<br>", $stmt->errno, $sql, $stmt->error, $addr->EmailType, $addr->Email, $ContactID );
	$this->dump();
	printf("\$stmt = <pre>%s</pre><br>", var_export($stmt, TRUE) );
}

This has been an issue since RC1, and is a bit frustrating.  In my case reloading the page to re-import works, eventually, but since the entire process takes about 5 minutes it is painful.
 [2004-09-02 06:53 UTC] georg@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 14:02:18 2014 UTC