php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61446 Can't prepare statement without getting a result
Submitted: 2012-03-19 23:25 UTC Modified: 2017-04-13 09:50 UTC
Votes:4
Avg. Score:3.2 ± 1.1
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: dasmag at gmail dot com Assigned: mysql (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.3.10 OS: ubuntu 11.04
Private report: No CVE-ID: None
 [2012-03-19 23:25 UTC] dasmag at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/mysqli.prepare
---

There are an error if I heven't got a result from statement.
Just execute the script with and without commented string.
And there are no description in the documentation.

Test script:
---------------
<?php
	$mysqli = new mysqli("localhost");
	$st = $mysqli->prepare("SELECT 1");
	$st->execute();
	// print_r($st->get_result()->fetch_assoc());
	
	$st = $mysqli->prepare("SELECT 2");
	$st->execute();
?>

Actual result:
--------------
Fatal error: Call to a member function execute() on a non-objec

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-02 12:25 UTC] uw@php.net
-Assigned To: +Assigned To: mysql
 [2012-05-02 12:25 UTC] uw@php.net
Very good find! Thanks! 

Andrey, mysqlnd sets an appropriate error message but we do not copy it into mysqli. mysqli has code for libmysql but not for mysqlnd. Maybe the copy was not needed for mysqlnd in the past?

>mysqlnd_stmt::prepare
| info : stmt=0
| info : query=SELECT 2
| >mysqlnd_conn_data::simple_command
| | info : command=STMT_PREPARE ok_packet=13 silent=0
| | >mysqlnd_conn_data::get_state
| | <mysqlnd_conn_data::get_state
| | >_mysqlnd_pestrdup
| | | info : file=mysqlnd.c       line= 326
| | | info : ptr=0x893d594
| | <_mysqlnd_pestrdup
| | info : adding error [Commands out of sync; you can't run this command now] to the list
| | >mysqlnd_conn_data::get_state
| | <mysqlnd_conn_data::get_state
| | error: Command out of sync. State=4
| <mysqlnd_conn_data::simple_command
| info : FAIL
<mysqlnd_stmt::prepare
>mysqlnd_stmt::dtor
 [2017-04-13 09:50 UTC] fjanisze@php.net
-Status: Assigned +Status: Closed
 [2017-04-13 09:50 UTC] fjanisze@php.net
In the latest release the error message is copied to mysqli. The problem in the script is that mysqli do not support buffered queries, before executing the second 'prepare' the user shall extract the result OR call store_result().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC