How Do I Call a MySQL Stored Procedure from PHP?

Patricia Arquette
Release: 2024-11-06 18:17:02
Original
364 people have browsed it

How Do I Call a MySQL Stored Procedure from PHP?

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:

  1. Establish a connection to the MySQL database using PHP's MySQLi extension.
  2. Prepare and execute the SQL statement to call the procedure:
$result = mysqli_query($connection, "CALL getTreeNodeName($nid)");
Copy after login
  1. Fetch the result from the database:
while ($row = mysqli_fetch_array($result)){
    echo $row[0] . " - " . $row[1];
}
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!