Hàm mysqli real_query () trong PHP
Ví dụ - Kiểu hướng đối tượng
Thực thi một truy vấn SQL duy nhất. Lưu trữ kết quả bằng store_result ():
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
$mysqli -> real_query("SELECT * FROM Persons");
if ($mysqli -> field_count) {
$result = $mysqli -> store_result();
$row = $result -> fetch_row();
// Free result set
$result -> free_result();
}
$mysqli -> close();
?>
Định nghĩa và Cách sử dụng
Hàm real_query () / mysqli_real_query () thực thi một truy vấn SQL duy nhất. Kết quả có thể được truy xuất hoặc lưu trữ bằng các hàm store_result () hoặc use_result ().
Cú pháp
Phong cách hướng đối tượng:
$mysqli -> real_query(query)
Phong cách thủ tục:
mysqli_real_query(connection, query)
Giá trị tham số
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
query | Required. The query to be executed |
Chi tiết kỹ thuật
Giá trị trả lại: | ĐÚNG về thành công. FALSE khi thất bại |
---|---|
Phiên bản PHP: | 5+ |
❮ Tham khảo PHP MySQLi