Despite the misconception, it is indeed possible to manage stored procedures using phpMyAdmin. To achieve this, follow these steps:
CREATE PROCEDURE sp_test() BEGIN SELECT 'Number of records: ', count(*) from test; END//
To execute a stored procedure in PHP, use a CALL query, as exemplified below:
<?php $con = new mysqli("localhost", "username", "password", "database"); if ($con->connect_error) { die("Connection failed: " . $con->connect_error); } $sp_query = "CALL sp_test();"; if ($con->query($sp_query) === TRUE) { $result = $con->query("SELECT @num_records"); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); echo "Number of records: " . $row["@num_records"]; } else { echo "No records found"; } } else { echo "Error calling stored procedure: " . $con->error; } $con->close(); ?>
Stored procedures can be altered or dropped through phpMyAdmin. They can be found in the "Routines" fieldset below the tables in the Structure tab.
Employing stored procedures with PHP offers several benefits:
The above is the detailed content of How Can I Manage and Utilize Stored Procedures in phpMyAdmin and PHP?. For more information, please follow other related articles on the PHP Chinese website!