Home > Database > Mysql Tutorial > body text

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

DDD
Release: 2024-11-17 08:14:03
Original
962 people have browsed it

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//
Copy after login

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()");
Copy after login
  1. You can fetch the results of the stored procedure like a regular query:
while ($row = $result->fetch_assoc()) {
  echo $row['Number of records: '];
}
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template