PHP MySQL Stored Procedure Getting Number of Rows Returned

Hi

Please take a look at my code snippet. Works fine, however I don’t know how to get the number of rows returned from a MySQL stored procedure so that I can handle it accordingly. Any ideas please?

Thanks.

[php]

<?php require ('mysqli_connect.php'); // Connect to the Db. $sql = "CALL customers_for_rep(?, ?)"; $stmt = $dbc->prepare($sql); if ($dbc->errno) {die($dbc->errno.":: ".$dbc->error);} $stmt->bind_param("is", $i_user_id, $i_firstName); $i_user_id = 2; $i_firstName = "David"; $stmt->execute( ); $rows = $stmt->num_rows; if ($dbc->errno) {die($dbc->errno.": ".$dbc->error);} $stmt->bind_result($first_name, $last_name); echo "Rows returned: " . $rows . ""; $buf = ""; $buf .= ''; $buf .= ' '; $buf .= ' '; $buf .= ' '; $buf .= ' '; while ($stmt->fetch( )) { $buf .= ''; $buf .= ' '; $buf .= ' '; $buf .= ''; } $buf .= '
First NameLast Name
' . $first_name . '' . $last_name . '
'; echo $buf; echo "

made it."; mysqli_close($dbc); ?>

[/php]

DELIMITER $$
DROP PROCEDURE IF EXISTS customers_for_rep$$
CREATE PROCEDURE customers_for_rep
(
    IN i_user_id INT,
    IN i_firstName VARCHAR(100)
)
BEGIN
    SELECT first_name, last_name
    FROM users
    WHERE users_id > i_user_id;
END $$
DELIMITER ;
Sponsor our Newsletter | Privacy Policy | Terms of Service