Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Not an Issue
-
Affects Version/s: 1.5.1
-
Fix Version/s: 1.8.4
-
Component/s: Zend_Db_Adapter_Mysqli
-
Labels:None
-
Fix Version Priority:Should Have
Description
I need your help with a stored procedure in MySql using ZendFramework:
This is the stored:
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`p1` $$
CREATE DEFINER=`root`@`%` PROCEDURE `p1`(IN p_in INT, OUT p_out INT)
BEGIN
SELECT concat("VALORE DI p_in: ", p_in) as VALORE;
- Creo il valore di output
SET p_out = p_in * 100;
END $$
DELIMITER ;
This is the result on MySql command prompt:
mysql> SET @prova = 100;
Query OK, 0 rows affected (0.00 sec)
mysql> CALL p1 (9, @prova);
-------------------
| VALORE |
-------------------
| VALORE DI p_in: 9 |
-------------------
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.09 sec)
mysql> SELECT @prova;
--------
| @prova |
--------
| 900 |
--------
1 row in set (0.02 sec)
Now the php script:
<?php
require_once 'Zend/Db.php';
require_once 'Zend/Db/Adapter/Mysqli.php';
$db = new Zend_Db_Adapter_Mysqli(array(
'host' => 'localhost',
'username' => 'mito',
'password' => 'test',
'dbname' => 'test'
));
$prova = 0;
$out_in = 100;
$sql = "SET @prova = 100";
$stmt = new Zend_Db_Statement_Mysqli($db, $sql);
$stmt->execute();
$sql = "CALL p1 (?, @prova)";
$stmt = new Zend_Db_Statement_Mysqli($db, $sql);
$stmt->execute(array(60));
$row = $stmt->fetchAll();
print "<pre>";
print_r($row);
print "</pre>";
//$nextRowset = $stmt->nextRowset();
$closeCursor = $stmt->closeCursor();
$close = $stmt->close();
// Retrieve variable
$sql = "SELECT @prova";
$stmt2 = new Zend_Db_Statement_Mysqli($db, $sql);
$stmt2->execute();
$prova = $stmt2->fetch();
echo "value: " . $prova;
?>
Running the script I have an error at this istruction: $stmt2 = new Zend_Db_Statement_Mysqli($db, $sql);
Debug Error: /cabelweb/lib/PHP/ZendFramework-1.5.1/library/Zend/Db/Statement/Mysqli.php line 85 - Uncaught exception 'Zend_Db_Statement_Mysqli_Exception' with message 'Mysqli prepare error: Commands out of sync; you can't run this command now' in /cabelweb/lib/PHP/ZendFramework-1.5.1/library/Zend/Db/Statement/Mysqli.php:85
Stack trace:
#0 /cabelweb/lib/PHP/ZendFramework-1.5.1/library/Zend/Db/Statement.php(109): Zend_Db_Statement_Mysqli->_prepare('SELECT @prova')
#1 /cabelweb/bin/PHP/com/cabel/apps/test/zend_framework/mysql/stored_exec_ZF.php(35): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Mysqli), 'SELECT @prova')
#2 {main}
thrown
Why this behavior? Where is the problem?
Thanks in advance
Hi Shlomo,
I think we have a fix for this inside ZF 1.6 coming up soon.
If you are interested in a patch, please check this:
http://framework.zend.com/code/changelog/Standard_Library?cs=9738
more specfifically, this file and change:
http://framework.zend.com/code/browse/Standard_Library/trunk/library/Zend/Db/Statement/Mysqli.php?r1=9573&r2=9738
As you can see, the closeCursor() method gets a next_result call to the Mysqli statement object. The reason this is necessary is b/c stored procedure calls always return multiple result sets (presumably the last result set is for the exit status code). Please try this and let me know if it works.
Thanks!
Ralph Schindler