PHP mysqli Preparation () وظيفة
مثال - أسلوب كائن المنحى
تحضير جملة SQL للتنفيذ:
<?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();
}
// prepare and bind
$stmt = $mysqli -> prepare("INSERT INTO
MyGuests (firstname, lastname, email) VALUES (?, ?, ?)");
$stmt ->
bind_param("sss", $firstname, $lastname, $email);
// set parameters and
execute
$firstname
= "John";
$lastname = "Doe";
$email = "[email protected]";
$stmt -> execute();
$firstname = "Mary";
$lastname = "Moe";
$email = "[email protected]";
$stmt -> execute();
echo "New records created successfully";
$stmt -> close();
$mysqli -> close();
?>
التعريف والاستخدام
تُستخدم وظيفة تحضير () / mysqli_prepare () لإعداد جملة SQL للتنفيذ.
بناء الجملة
النمط الموجه للكائن:
$mysqli -> prepare(query)
الأسلوب الإجرائي:
mysqli_prepare(connection, query)
قيمه المعامل
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
query | Required. Specifies an SQL query. Note: Do not add semicolon to the end of the query! |
تفاصيل تقنية
قيمة الإرجاع: | بيان كائن على النجاح. خطأ في الفشل |
---|---|
إصدار PHP: | 5+ |
❮ PHP مرجع MySQLi