批改狀態(tài):未批改
老師批語:
<?php require 'mysqli_connect2.php'; $sql = "UPDATE IGNORE staff SET name=?,sex=?,age=?,salary=? WHERE staff_id=?;";// 準(zhǔn)備 sql 語句 $stmt = mysqli_stmt_init($db);//創(chuàng)建并初始化預(yù)處理對象stmt mysqli_stmt_prepare($stmt, $sql);//用stmt對象處理當(dāng)前預(yù)處理語句 mysqli_stmt_bind_param($stmt, 'siiii', $name, $sex, $age, $salary, $staff_id);// 變量與語句中的占位符進(jìn)行綁定 $staff_id = 18; $name = '八荒六唯我獨(dú)尊功9'; $sex = 0; $age = 99; $salary = 99999; mysqli_stmt_execute($stmt);//執(zhí)行 sql 語句 echo '更新成功,主鍵id是:'.$staff_id; mysqli_stmt_close($stmt); mysqli_close($db); ?>
<?php require 'mysqli_connect2.php'; $sql = "DELETE FROM staff WHERE staff_id=?";// 準(zhǔn)備 sql 語句 $stmt = mysqli_stmt_init($db);//創(chuàng)建并初始化預(yù)處理對象stmt mysqli_stmt_prepare($stmt, $sql);//用stmt對象處理當(dāng)前預(yù)處理語句 mysqli_stmt_bind_param($stmt, 'd', $staff_id);// 變量與語句中的占位符進(jìn)行綁定 $staff_id = 21; mysqli_stmt_execute($stmt);//執(zhí)行 sql 語句 echo '刪除成功,主鍵id是:'.$staff_id; mysqli_stmt_close($stmt);//注銷預(yù)處理對象 mysqli_close($db);//關(guān)閉數(shù)據(jù)連接 ?>
WHERE 語句后面的變量綁定直接在參數(shù)后面加一個(gè)即可mysqli_stmt_bind_param($stmt, 'siiii', $name, $sex, $age, $salary, $staff_id);
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)