|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-11-12 22:27 UTC] kristaps dot kaupe at itrisinajumi dot lv
Description:
------------
Create MySQL test table and procedure:
--------------------------------------
CREATE TABLE `test_table` (
`id` int(10) unsigned NOT NULL auto_increment,
`txt` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO test_table (txt) VALUES ('test1');
CREATE PROCEDURE `test_proc`(IN p_id INT(10) UNSIGNED) READS SQL DATA DETERMINISTIC
BEGIN
SELECT * FROM test_table WHERE id = p_id;
END
Reproduce code:
---------------
// $db is mysqli object
if ($result = $db->query('CALL test_proc(1);')) {
$res = $result->fetch_assoc();
print_r($res);
$result->close();
}
else
echo '<br />'.$db->error.'<br />';
if ($result = $db->query('CALL test_proc(1);')) {
$res = $result->fetch_assoc();
print_r($res);
$result->close();
}
else
echo '<br />'.$db->error.'<br />';
Expected result:
----------------
Array
(
[id] => 1
[txt] => test1
)
Array
(
[id] => 1
[txt] => test1
)
Actual result:
--------------
Array
(
[id] => 1
[txt] => test1
)
Lost connection to MySQL server during query
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 16:00:01 2025 UTC |
Why I should use mysqli_multi_query()? Where is it documented, that I should use mysqli_multi_query() for stored procedures? But the following code with mysqli_multi_query() doesn't work either: ------- // $db is mysqli object if ($db->multi_query('CALL test_proc(1); CALL test_proc(1);')) { if ($result = $db->store_result()) { $res = $result->fetch_assoc(); print_r($res); $result->close(); } else echo '<br />No result!<br />'; $db->next_result(); if ($result = $db->store_result()) { $res = $result->fetch_assoc(); print_r($res); $result->close(); } else echo '<br />No result<br />'; } else echo '<br />'.$db->error.'<br />'; ----- Produces the following output: ----- Array ( [id] => 1 [txt] => test1 ) No result ----- (Expected was two identical results)