Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何为update查询准备语句?_Php_Mysql_Mysqli_Prepared Statement_Bindparam - Fatal编程技术网

Php 如何为update查询准备语句?

Php 如何为update查询准备语句?,php,mysql,mysqli,prepared-statement,bindparam,Php,Mysql,Mysqli,Prepared Statement,Bindparam,我有一个mysqli查询,代码如下: $db_usag->query("UPDATE Applicant SET phone_number ='$phone_number', street_name='$street_name', city='$city', county='$county', zip_code='$zip_code', day_date='$day_date', month_date='$month_date', year_date='$year_date' WHER

我有一个mysqli查询,代码如下:

$db_usag->query("UPDATE Applicant SET phone_number ='$phone_number', 
street_name='$street_name', city='$city', county='$county', zip_code='$zip_code', day_date='$day_date', month_date='$month_date',
 year_date='$year_date' WHERE account_id='$account_id'");

然而,所有的数据都是从HTML文档中提取的,所以为了避免错误,我想使用一个准备好的语句。我找到了,但没有更新示例。

更新与插入或选择操作相同。只需将所有变量替换为

$sql = "UPDATE Applicant SET phone_number=?, street_name=?, city=?, county=?, zip_code=?, day_date=?, month_date=?, year_date=? WHERE account_id=?";

$stmt = $db_usag->prepare($sql);

// This assumes the date and account_id parameters are integers `d` and the rest are strings `s`
// So that's 5 consecutive string params and then 4 integer params

$stmt->bind_param('sssssdddd', $phone_number, $street_name, $city, $county, $zip_code, $day_date, $month_date, $year_date, $account_id);
$stmt->execute();

if ($stmt->error) {
  echo "FAILURE!!! " . $stmt->error;
}
else echo "Updated {$stmt->affected_rows} rows";

$stmt->close();

除了最初的问题,您是否知道prepare语句是否支持unicode?我需要储存一些阿拉伯语names@ArabMichael:使您的数据库使用UTF8编码,将PHP的内部编码设置为UTF8(),您应该会没事的。Michael回答ArabMichael:D@DannyG做考古学?那时候,我经常用普通的迈克尔,而OP则是ArabMichael。就这样,呵呵,不知怎么地,我进入了这个问题,注意到了这个事实并评论道:)