For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > April 2005 > multi_query function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author multi_query function
Matej Baæo

2005-04-19, 8:55 pm

MySQL version 5.0.3
PHP version 5.0.4
Apache version 2.0.5

Source:

<?php

$mysqli = new mysqli("localhost", "user", "pass", "dbname");

$body = '';

/* // ver 1
$query = '
CREATE TEMPORARY TABLE IF NOT EXISTS proba(id INT UNSIGNED);
INSERT INTO proba VALUES (213), (7), (87);
';
$mysqli->multi_query($query);
*/

/* // ver 2
$query = 'CREATE TEMPORARY TABLE IF NOT EXISTS proba(id INT UNSIGNED);';
$mysqli->query($query);
$query = 'INSERT INTO proba VALUES (213), (7), (87);';
$mysqli->query($query);
*/

//control
$query = 'select * from proba;';
$result = $mysqli->query($query);
$body .= '<strong>Table proba:</strong><br>';
if ($result) {
while ($row = $result->fetch_row()) {
$body .= $row[0].'<br>';
}
$result->close();
}
else $body .=
'<strong>Error</strong>:'.$mysqli->errno.'<br>'.$mysqli->error.'<br><br>';

$query = 'DROP TABLE IF EXISTS proba;';
$result = $mysqli->query($query);

echo $body;

$mysqli->close();

?>

In short, ver 1 doesn't work, control output 2006: MySQL server has gone
away. Ver 2 works!
Question is why?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com