|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-11-04 21:28 UTC] waltermin at hotmail dot com
[2007-11-12 16:22 UTC] andrey@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 19:00:01 2025 UTC |
Description: ------------ Im trying to use MySQL 5.1 prepared statements that can return resultsets. Seems that mysqli can not prepare second statement even if free_result() was called for first. MySQL 5.0 doesn't able to return resultsets from stored procedures at all. smart:/home/dio# php --version PHP 5.2.4-1+b1 with Suhosin-Patch 0.9.6.2 (cli) (built: Oct 1 2007 10:35:56) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies smart:/home/dio# mysql --version mysql Ver 14.14 Distrib 5.1.22-rc, for pc-linux-gnu (i486) using EditLine wrapper Reproduce code: --------------- <?php $id = 39; $login; $md5password; $role; $fullname; $mysqli = new mysqli("localhost", "root", "", "tyres"); $stmtLoad = $mysqli->prepare("CALL spUserLoad(?)"); $stmtLoad->bind_param("i", $id); $stmtLoad->execute(); $stmtLoad->bind_result($id, $login, $md5password, $fullname, $role); $stmtLoad->fetch(); $stmtLoad->free_result(); var_dump($id, $login, $md5password, $fullname, $role); // Everything was loaded fine $stmtSave = $mysqli->prepare("CALL spUserUpdate(?, ?, ?, ?, ?)"); echo $mysqli->error; // Commands out of sync; you can't run this command now ?> Code of stored procedures: CREATE PROCEDURE `spUserLoad`(IN iId INT) BEGIN SELECT id, login, md5password, fullname, role FROM users WHERE id = iId; END CREATE PROCEDURE `spUserUpdate`(IN iLogin VARCHAR(256), IN iMd5password VARCHAR(32), IN iFullname VARCHAR(1024), IN iRole INT, IN iId INT) BEGIN IF (SELECT COUNT(*) FROM users WHERE login = iLogin AND id != iId) = 0 THEN UPDATE users SET login = iLogin, md5password = iMd5Password, fullname = iFullname, role = iRole WHERE id = iId; ELSE SELECT 2 AS SP_ERROR_CODE; END IF; END Expected result: ---------------- The new statement should be prepared for calling. And be able to return resultsets too Actual result: -------------- The new statement can not be prepared due to "Commands out of sync; you can't run this command now" error :(