I have problem with a stored procedure where i use a cursor, so i made a test code to spot the problem but its still a mystery for me, here is the test codes:
Stored proc. body named 'Test1':
SELECT 'ok1';
Stored proc. body named 'Test2':
DECLARE testCursor CURSOR FOR SELECT 'stuff';
OPEN testCursor;
CLOSE testCursor;
SELECT 'ok2';
Php test code:
$mysql_obj = new mysqli($sqlserver, $sqluser, $sqlpass, $sqldatabase);
$statement = $mysql_obj->prepare('CALL Test1()');
$statement->execute();
$result = $statement->get_result();
if($result === false) die('bad result');
if($result->num_rows === 0) die('row expected');
$row = $result->fetch_row();
if($row === NULL) die('fetch_row error');
echo 'Got: ' . $row[0];
Run results the message "Got: ok1"
as expected, but if i change the call to Test2
the message will be "row expected".
The really confusing in this problem that in phpmyadmin CALL Test1();
and the CALL Test2();
command both results one row with the "ok1"/"ok2"
value (tested in dbForge Studio Express, it's good too).
What am I missing?