I'm a new to php and am having trouble getting a result set from a stored procedure, I'd like the answer in a procedural format if possible.
The stored procedure is as follows:
DROP PROCEDURE IF EXISTS getJobs;
DELIMITER $$
CREATE PROCEDURE getJobs(IN inputName VARCHAR(50))
BEGIN
SELECT JobNo FROM jobs WHERE PersonnelName= inputName;
END $$
DELIMITER ;
In MySQL Workbench this returns 30539
I've come up with the following php code.
<?php
//imports the connection
require "conn.php";
$name = "chrisf";
$call = mysqli_prepare($conn, 'CALL getJobs(?)');
mysqli_stmt_bind_param($call, 's', $name);
mysqli_stmt_execute($call);
$result = mysqli_use_result($conn);
//debug to check the result
echo '<pre>'; print_r($result); echo '</pre>';
//loop the result set and echo
while ($row = mysqli_fetch_array($result)){
//the command I expect to output the result
echo "Entry" . $row[0] . "<br>";
//debug to check the result
echo "Entry" . $row . "<br>";
}
$conn->close();
?>
When run this provides the following output:
mysqli_result Object
(
[current_field] => 0
[field_count] => 1
[lengths] =>
[num_rows] => 0
[type] => 1
)
Entry
EntryArray
As the mysqli_result Object disappears if I use an input which returns no results, this seems to be close but it doesn't actually contain the data.
Thanks in advance.