Home > Database > Mysql Tutorial > How Can I Create and Call Stored Procedures Using phpMyAdmin and PHP?

How Can I Create and Call Stored Procedures Using phpMyAdmin and PHP?

Susan Sarandon
Release: 2024-11-17 00:56:03
Original
758 people have browsed it

How Can I Create and Call Stored Procedures Using phpMyAdmin and PHP?

Managing and Utilizing Stored Procedures in phpMyAdmin and PHP

Creating and managing stored procedures through phpMyAdmin is possible, despite misconceptions. To create a stored procedure in phpMyAdmin, navigate to the SQL tab and follow these steps:

  • Change the "Delimiter" field to "//"
  • Insert the CREATE PROCEDURE query, specifying the procedure name and body
  • Run the query

Upon creation, the stored procedure will appear under the "Routines" section in the "Structure" tab.

To utilize the stored procedure in PHP, execute a CALL query:

<?php
// Connect to MySQL
$conn = mysqli_connect("host", "user", "password", "database");

// Call stored procedure
$result = mysqli_query($conn, "CALL sp_test()");

// Process results
while ($row = mysqli_fetch_array($result)) {
    echo $row[0]; // Display column value
}

// Close connection
mysqli_close($conn);
?>
Copy after login

The above is the detailed content of How Can I Create and Call Stored Procedures Using phpMyAdmin and 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