1

我正在通过 php mysqli 运行以下查询$con->query($sql);

PHP代码:

$sql = 'UPDATE registrations SET '.$update_columns_list.' WHERE registrationkey = "'.$registration['RegistrationKey'].'"';
echo "RESULT: ".$result = $con->query($sql);

上例中的值$sql

UPDATE registrations SET referenceid = "4469731" and action = "newregistration" and status = "newregistration" and registrationdatetimegmt = "1363371386" and billingmonth = "2013-03" and accessexpirationdatetimegmt = "1373957999" and returnurl = "https://api.mywebsite.com/login.aspx?siteid=209" and lastmodifieddatetimegmt = "1363371398" and studentkey = "12345-67890-12345-67890" and firstname = "amanda" and lastname = "hemingway" and email = "amandamhemingway@trashymail.com" and phonenumber = "111-111-1111" and city = "city" and state = "ca" and postalcode = "90210" and country = "us" and coursecode = "ABC-406" and coursetitle = "example course title" and courseproductcode = "t3310" WHERE registrationkey = "12345-67890-12345-67890"

当我运行此查询时,一切似乎都很好(我收到“成功”消息并且受影响的行数与预期的一样)。但是,当我通过 phpMyAdmin 查看数据库中受影响的行时,我不断在“referenceid”列中找到 1 或 0 值。没有其他脚本影响此表或数据库。我无法确定何时放置 0 而不是 1 的任何模式。

referenceidkeyid字段都是' VARCHAR(100)s。

4

2 回答 2

3

您正在执行的更新语句执行布尔运算。这是我不喜欢的mysql中的一种行为。

当前的更新语句如下所示:

UPDATE tableName SET col1 = 2 AND col2 = 3

并且MySQL服务器不会抛出任何异常,因为语法是允许的,并且它读取为:

UPDATE tableName SET col1 = (2 AND (col2 = 3))

如果要更新多个列,请使用,not 分隔列AND

UPDATE registrations 
SET    referenceid = "4469731",
       action = "newregistration", .....
于 2013-03-25T14:59:36.690 回答
1

When you update you don't add columns with and, rather than with a comma, so your Update should look like:

UPDATE registrations 
 SET referenceid = "4469731",
     action = "newregistration",
     status = "newregistration",
     registrationdatetimegmt = "1363371386",
     billingmonth = "2013-03",
     accessexpirationdatetimegmt = "1373957999",
     returnurl = "https://api.mywebsite.com/login.aspx?siteid=209",
     lastmodifieddatetimegmt = "1363371398",
     studentkey = "12345-67890-12345-67890",
     firstname = "amanda",
     lastname = "hemingway",
     email = "amandamhemingway@trashymail.com",
     phonenumber = "111-111-1111",
     city = "city",
     state = "ca",
     postalcode = "90210",
     country = "us",
     coursecode = "ABC-406",
     coursetitle = "example course title",
     courseproductcode = "t3310"
 WHERE registrationkey = "12345-67890-12345-67890"
于 2013-03-25T15:03:43.573 回答