Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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 MySQL:使用准备好的语句从表中删除两列_Php_Mysql_Prepared Statement - Fatal编程技术网

Php MySQL:使用准备好的语句从表中删除两列

Php MySQL:使用准备好的语句从表中删除两列,php,mysql,prepared-statement,Php,Mysql,Prepared Statement,我试图在不删除整行的情况下更新两列。以下是我正在使用的: $sql='update users set token='',timestamp='' where token=?'; $stmt=$db_con->stmt_init(); $stmt->prepare($sql_3); $stmt->bind_param('s',$token); $stmt->execute(); 但是,它给了我一个错误:T_常量_封装的_字符串。现在,当我通过My

我试图在不删除整行的情况下更新两列。以下是我正在使用的:

$sql='update users set token='',timestamp='' where token=?';
   $stmt=$db_con->stmt_init();
   $stmt->prepare($sql_3);
   $stmt->bind_param('s',$token);
   $stmt->execute();
但是,它给了我一个错误:T_常量_封装的_字符串。现在,当我通过MySQL CLI使用查询时,查询工作正常,因为
updateusers set token='',timestamp='',其中token='blahblah'我该如何解决这个问题?

您应该使用

$sql="update users set token='',timestamp='' where token=?";
请注意字符串开头和结尾的双引号(“)

由于您在字符串中使用了多个单引号,PHP不理解这一点,将抛出一个错误。您需要告诉PHP转义引号。您可以通过两种方式来完成

1) 通过在引号前面使用PHP的
\
转义字符

'update users set token=\'\',timestamp=\'\' where token=?';
2) 对字符串使用双引号,而不是单引号

"update users set token=\'\',timestamp=\'\' where token=?";
两者都应该起作用。

您应该使用

$sql="update users set token='',timestamp='' where token=?";
请注意字符串开头和结尾的双引号(“)

因为您在字符串中使用了多个单引号,所以PHP不理解这一点,并将抛出一个错误。您需要告诉php转义引用。你可以用两种方法来做

1) 通过在引号前面使用PHP的
\
转义字符

'update users set token=\'\',timestamp=\'\' where token=?';
2) 对字符串使用双引号,而不是单引号

"update users set token=\'\',timestamp=\'\' where token=?";
两者都应该起作用。

使用此选项

$sql="update users set token='',timestamp='' where token=?";
您可以在此处找到有关如何转义字符串的详细信息。

使用这个

$sql="update users set token='',timestamp='' where token=?";
您可以在此处找到有关如何转义字符串的详细信息。

在此,我想通知您,as查询是单引号的,您在查询字符串中多次使用单引号。PHP将接受从第一个引号到下一个引号的字符串,这就是为什么会出现错误,但在命令行中不会生成错误

$sql='update users set token='',timestamp='' where token=?'; to
$sql="update users set token='',timestamp='' where token=?";

在这里,我想告诉您,因为查询是在单引号中进行的,并且您在查询字符串中多次使用单引号。PHP将接受从第一个引号到下一个引号的字符串,这就是为什么会出现错误,但在命令行中不会生成错误

$sql='update users set token='',timestamp='' where token=?'; to
$sql="update users set token='',timestamp='' where token=?";

是的。我上个月开始的。爱它到目前为止:)是的。我上个月开始的。到目前为止我都很喜欢:)