While it's true that phpMyAdmin doesn't provide direct management functionality for stored procedures, don't despair! There's a straightforward solution using queries.
1. Using Queries:
Using the SQL tab, create a new query and enter the following code (modify as needed):
CREATE PROCEDURE sp_test() BEGIN SELECT 'Number of records: ', count(*) from test; END//
2. Set the Delimiter:
From the "Delimiter" field on the SQL tab, set it to "//".
1. Execute a CALL Query:
To call the stored procedure from PHP, use the mysqli_query() function:
$mysqli = new mysqli("localhost", "username", "password", "dbname"); $mysqli->query("CALL sp_test()");
2. Retrieve Results:
After executing the query, you can retrieve the stored procedure's results using mysqli_fetch_array():
if ($result = $mysqli->query("CALL sp_test()")) { while ($row = $result->fetch_array(MYSQLI_ASSOC)) { echo $row['Number of records: ']; } }
The above is the detailed content of How to Seamlessly Integrate Stored Procedures with PHP?. For more information, please follow other related articles on the PHP Chinese website!