php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35333 MySQL server goes away after multi_query and before the next query.
Submitted: 2005-11-22 16:06 UTC Modified: 2005-11-26 06:32 UTC
From: camka at email dot ee Assigned: georg (profile)
Status: Not a bug Package: MySQLi related
PHP Version: 5CVS-2005-11-22 (snap) OS: WinXP, Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
22 + 3 = ?
Subscribe to this entry?

 
 [2005-11-22 16:06 UTC] camka at email dot ee
Description:
------------
After running several "non-select" queries with mysqli::multi_query() it's impossible to run mysqli::query() method with some "select" query, the mysqli::error says "MySQL server has gone away".

If iterate through all the results of mysqli::multi_query() using mysqli::next_result(), then the program won't issue the "gone away" problem and the following mysqli::query() runs as expected.

tried with the latest cvs snapshot.
PHP Version 5.0.6-dev Nov 22 2005 10:22:22 

On one machine it needs to hit browser's "refresh" button to get an error, on other machine the error comes every single program run.

Reproduce code:
---------------
<?php
$s = new mysqli('localhost', '******', '*******', '*****');
$s -> multi_query('drop temporary table if exists z1; create temporary table z1(u int);');

// if uncomment the following line, the script works as expected
// while ($s->next_result());

echo "- ",$s -> error,"<br>";
$s -> query("SELECT count(*) from z1");
echo "- ",$s -> error,"<br>";
$s->close();
?>qu

Expected result:
----------------
- 
-
(two empty errors)

Actual result:
--------------
- 
- MySQL server has gone away

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-22 16:07 UTC] camka at email dot ee
may be related to bug #31668
 [2005-11-22 19:42 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

After executing mysqli_multi_query you have first process the resultsets before sending any another statement to the server, otherwise your socket is still blocked.

Please note that even if your multi statement doesn't contain SELECT queries, the server will send result packages containing errorcodes (or OK packet) for single statements. 
 [2005-11-22 23:15 UTC] camka at email dot ee
but still, if i use selects in multi_query:
$s -> multi_query("select 1;select 2");

and then 

$s -> query("select 3");

i get more understandable error

- 2014 - Commands out of sync; you can't run this command now

Why then the server goes away in case of non-select queries?
Out of sync error would be less confusing.
 [2005-11-23 09:30 UTC] sniper@php.net
Report that to Mysql, it is not PHP problem.
 [2005-11-25 11:12 UTC] camka at email dot ee
Cannot repeat the problem using C mysql API. Looks like still the mysqli extension error.

http://bugs.mysql.com/bug.php?id=15181
 [2005-11-25 12:58 UTC] tony2001@php.net
Georg, as mysql dude, could you explain what's the problem with MySQL Client and why it's not PHP problem?
 [2005-11-26 06:32 UTC] georg@php.net
Can't repeat:

<?php
$mysql = new mysqli('localhost', 'test', 'php', 'test');

printf("Client version: %s\n", $mysql->client_version);
printf("Server version: %s\n", $mysql->server_version);

$mysql->multi_query('drop temporary table if exists z1; create temporary
table z1(u int);');
printf("Error: %s\n", $mysql->error);

$mysql->multi_query("SELECT 1;SELECT 2");
printf("Error: %s\n", $mysql->error);

$mysql->query("SELECT count(*) from z1");
printf("Error: %s\n", $mysql->error);
$mysql->close();
?>

Output:

php -f 35333.php

Client version: 50015
Server version: 50015
Error:
Packets out of order (Found: 2, expected 1)
Error: Lost connection to MySQL server during query
Error: MySQL server has gone away
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC