Home >Database >Mysql Tutorial >How Can I Call a MySQL Stored Procedure from PHP?
Problem:
A MySQL stored procedure named getTreeNodeName has been created, and the task is to invoke it using PHP code.
Solution:
Using MySQLi:
// Enable error reporting mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // Connect to database $connection = mysqli_connect("hostname", "user", "password", "db", "port"); // Run the stored procedure $result = mysqli_query($connection, "CALL getTreeNodeName"); // Loop the result set while ($row = mysqli_fetch_array($result)) { echo $row[0] . " - " . + $row[1]; }
Using MySQL:
Incorrect Method:
// DO NOT USE THIS METHOD $connection = mysql_connect("hostname", "user", "password", "db", "port");
This method is deprecated and may cause errors.
Note:
It's recommended to use mysqli instead of mysql for improved stability and performance.
The above is the detailed content of How Can I Call a MySQL Stored Procedure from PHP?. For more information, please follow other related articles on the PHP Chinese website!