🚀 تخفیف ۳۵٪ + ۳.۵ میلیون هدیه! برنامه‌نویسی رو الان شروع کن - فقط امروز!
۰ ثانیه
۰ دقیقه
۰ ساعت
۱ مهران
مثال برای UPDATE یا Delete با Bind_Param
جامعه پی اچ پی ایجاد شده در ۲۵ تیر ۱۴۰۲

سلام لطفا مثالی برای کار با UPDATE یا DELETE با bind بزنید

سلام،

مثالی برای UPDATE با mysqli:

$mysqli = new mysqli("localhost", "root", "", "mydb");
// Check if the connection was successful
if ($mysqli->connect_errno) {
    die("Connection failed: " . $mysqli->connect_error);
}
// Prepare an update statement
$stmt = $mysqli->prepare("UPDATE users SET name = ?, email = ? WHERE id = ?");
// Bind the values
$stmt->bind_param("sss", $name, $email, $id);
// Execute the statement
$stmt->execute();
// Check if the statement was successful
if ($stmt->affected_rows > 0) {
    echo "The record was updated successfully";
} else {
    echo "The record was not updated";
}

مثالی برای DELETE:

// Prepare a delete statement
$stmt = $mysqli->prepare("DELETE FROM users WHERE id = ?");
// Bind the value
$stmt->bind_param("s", $id);
// Execute the statement
$stmt->execute();
// Check if the statement was successful
if ($stmt->affected_rows > 0) {
    echo "The record was deleted successfully";
} else {
    echo "The record was not deleted";
}
بهترین پاسخ
محسن موحد ۲۵ تیر ۱۴۰۲، ۰۹:۳۲