Receive record set from MySQL stored procedure with cursor
Hello,
I need help.
I have the table:
CREATE TABLE IF NOT EXISTS `kbhead` (
`headid` int(10) NOT NULL AUTO_INCREMENT,
`hdname` char(50) NOT NULL,
`hdstat` char(1) NOT NULL,
PRIMARY KEY (`headid`)
) ENGINE=InnoDB;
and I have the some rows in this table.
I have the stored procedure for work with data in this table:
create procedure pget_info2 ()
begin
declare mheadid int;
declare mhdname char(50);
declare mhdstat char(1);
declare mnorows boolean;
declare ckbhead cursor for
select headid, hdname, hdstat
from kbhead
where headid <= 10;
declare continue handler for not found
set mnorows = true;
open ckbhead;
the_loop: loop
fetch ckbhead
into mheadid, mhdname, mhdstat;
if mnorows then
close ckbhead;
leave the_loop;
end if;
select mheadid, mhdname, mhdstat;
end loop the_loop;
end
When I call this procedure from mysql command line I have receive the correct record set;
Now I should use this procedure from PHP-script.
I have written following code:
$conn = mysql_connect('localhost', 'xxxx', 'xxxx', false, 65536);
mysql_select_db('xxxx', $conn);
$rs = mysql_query("call pget_info2();");
while ($row = (mysql_fetch_assoc($rs)))
{
print_r($row);
echo "<br/>";
}
mysql_close($conn);
Unfortunately this script receives only one row from record set. This is the first row.
How can I get all rows from record set in PHP-script?
P.S. Excuse for my English