stored procedure using Mysqli
Hi Sach,
I am also facing the similar problem. I am using Zend 1.5 and Php 5.2.0. I am facing problem while I am trying to get the records from the database. I am using stored procedures with Mysqli.
My code is:-
In config file, I wrote:-
; Database Settings
db.adapter = Mysqli
db.dbname = test
db.hostname = localhost
db.username = root
db.password = test
In bootstrap file, I wrote:-
// setup database
$params = array(
'host' => $config->db->hostname,
'username' => $config->db->username,
'password' => $config->db->password,
'dbname' => $config->db->dbname,
'driver_options' => ''
);
$db = Zend_Db::factory($config->db->adapter,$params);
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('db', $db);
In the main model file where I am trying to fetch the record, I just called write these statements:-
/*
* Open the database registry
*/
$db = Zend_Registry::get('db');
$stmt = $db->prepare("call uspSelectUsers()");
$stmt->execute();
$result = $stmt->fetch();
It gives me warning messages and doesn't give any result.
Warning: Invalid argument supplied for foreach() in /home/test/public_html/test/library/Zend/Db/Statement/Mysqli .php on line 289
Warning: array_combine() expects parameter 1 to be array, null given in /home/test/public_html/test/library/Zend/Db/Statement/Mysqli .php on line 299
When I print the mysql error, there is nothing in the string means there is no mysql error.
When I wrote the complete sql statement in the prepare statement rather than calling a stored procedure, I got the results. But I didn't get any result by using stored procedure.
Also, the interesting thing is when I use the same to insert a record in the table by using stored proceudre, the record inserted successfully. To insert a record I just used the simple query in my model file
/*
* Open the database registry
*/
$db = Zend_Registry::get('db');
$stmt = $db->prepare("call uspInsertUsers($name, $email)");
$stmt->execute();
The record inserted successfully in the table.
So, please help me to sort out this issue. I searched all over the net but I didn't get any useful result. So any little help is appreciable.
I am looking forward for your quick response.
Thanks,
San
|