BIG
Call stored procedure sample code using PHP
#MariaDB console
# Create stored procedure
DELIMITER $$
CREATE PROCEDURE GetProductById(IN product_id INT)
BEGIN
SELECT * FROM products WHERE id = product_id;
END $$
DELIMITER ;
# Call stored procedure
CALL GetProductById(5);
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$product_id = 5;
$stmt = $conn->prepare("CALL GetProductById(?)");
$stmt->bind_param("i", $product_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
}
} else {
echo "No results";
}
$stmt->close();
$conn->close();
?>
LIST
'!!...PHP > !!...SAMPLE' 카테고리의 다른 글
[PHP]18_입력받은 문자열에서 숫자만 추출하기 (0) | 2023.09.05 |
---|---|
[PHP]16_curl 을 이용한 파일 전송 샘플코드 (0) | 2023.02.13 |
[PHP]15_http reqeust sample code (0) | 2023.02.08 |
[PHP]14_openai API ( chatGPT )연동 샘플 코드 (0) | 2023.02.08 |
[PHP]13_shell_exec Sample Code (0) | 2022.12.23 |