Calling MySQL Stored Procedures from PHP
Invoking MySQL stored procedures from PHP code enables database operations to be executed efficiently. This article explores the process of calling a stored procedure within PHP, utilizing the MySQL client and server versions mentioned.
To call a stored procedure named getTreeNodeName with a parameter nid, follow these steps:
$result = mysqli_query($connection, "CALL getTreeNodeName($nid)");
while ($row = mysqli_fetch_array($result)){ echo $row[0] . " - " . $row[1]; }
The above code snippet assumes that the getTreeNodeName procedure returns a single row with two columns. Adjust the code accordingly if different result structures are expected.
Note: The provided solution utilizes mysqli instead of the deprecated mysql_* functions, ensuring compatibility and better performance.
The above is the detailed content of How Do I Call a MySQL Stored Procedure from PHP?. For more information, please follow other related articles on the PHP Chinese website!