How to Create and Execute Stored Procedures in phpMyAdmin
Creating and executing stored procedures in phpMyAdmin is a simple process that can enhance your database management capabilities. Here's a step-by-step guide to help you get started:
Creating a Stored Procedure
For Example:
CREATE PROCEDURE calculate_age(id VARCHAR(10)) BEGIN SELECT name, (DATE(NOW()) - DATE_OF_BIRTH)/365 AS age FROM people WHERE id = id; END
Calling a Stored Procedure Using MVC Architecture
In an MVC architecture, you can call a stored procedure from your controller. Here's a simplified example using PHP and mysqli:
<code class="php">// Get database connection $db = new mysqli('127.0.0.1:3306', 'username', 'password', 'database'); // Prepare statement to call stored procedure $stmt = $db->prepare("CALL get_sales(?)"); // Bind parameter to stored procedure $stmt->bind_param('i', $order_id); // Execute stored procedure $stmt->execute(); // Get result from stored procedure $result = $stmt->get_result();</code>
By following these steps, you can easily create and execute stored procedures in phpMyAdmin and leverage them in your MVC applications to perform complex database operations efficiently.
The above is the detailed content of How Do You Create and Execute Stored Procedures in phpMyAdmin?. For more information, please follow other related articles on the PHP Chinese website!