Home >Database >Mysql Tutorial >How to Manage and Use MySQL Stored Procedures with phpMyAdmin and PHP?

How to Manage and Use MySQL Stored Procedures with phpMyAdmin and PHP?

DDD
DDDOriginal
2024-11-17 08:14:031023browse

How to Manage and Use MySQL Stored Procedures with phpMyAdmin and PHP?

Managing Stored Procedures with phpMyAdmin and Integrating Them into PHP

While it may seem that phpMyAdmin lacks the ability to directly manage stored procedures, it is actually possible using SQL queries.

Creating Stored Procedures in phpMyAdmin

  1. Navigate to the SQL tab in phpMyAdmin.
  2. Change the "Delimiter" field to "//".
  3. Enter the following SQL query to create a stored procedure:
CREATE PROCEDURE sp_test()
BEGIN
  SELECT 'Number of records: ', count(*) from test;
END//

Using Stored Procedures in PHP

  1. To execute a stored procedure from PHP, use a CALL query:
$mysqli = new mysqli($host, $user, $password, $database);
$result = $mysqli->query("CALL sp_test()");
  1. You can fetch the results of the stored procedure like a regular query:
while ($row = $result->fetch_assoc()) {
  echo $row['Number of records: '];
}

The above is the detailed content of How to Manage and Use MySQL Stored Procedures with phpMyAdmin and PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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