1. Create the database and table (test | user)
2. Create the procedure. “new_proc” (I used EMS SQL Manager 2005)
CREATE PROCEDURE `new_proc`() NOT DETERMINISTIC CONTAINS SQL SQL SECURITY INVOKER COMMENT '' SELECT * FROM `user`;
3. Setup your PHP code as follows:
<?php
$hostname_myConnection = "localhost";
$database_myConnection = "test";
$username_myConnection = "root";
$password_myConnection = "";
$mysqli = new mysqli($hostname_myConnection, $username_myConnection, $password_myConnection);
$mysqli->select_db($database_myConnection);
?>
<?php
$Recordset = mysqli_query($mysqli, "CALL new_proc()") or die(mysql_error());
$row_Recordset = mysqli_fetch_assoc($Recordset);
$totalRows_Recordset = mysqli_num_rows($Recordset);
$i = 1;
do {
echo ("username: ".$row_Recordset['login']);
echo (" password: ".$row_Recordset['password']);
echo("<br>");
$i++;
$row_Recordset = mysqli_fetch_assoc($Recordset);
} while ($totalRows_Recordset >= $i);
?>


0 Responses to “Using Stored Procedures (MySql and PHP) in 3 Steps”