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 .= 'First Name | '; $buf .= 'Last Name | '; $buf .= '
' . $first_name . ' | '; $buf .= '' . $last_name . ' | '; $buf .= '
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 ;