Php 更新数据库集。。。用0或1填充一个特定的VARCHAR,而不管我设置的值是多少
我正在通过php mysqliPhp 更新数据库集。。。用0或1填充一个特定的VARCHAR,而不管我设置的值是多少,php,mysql,database,sql-update,Php,Mysql,Database,Sql Update,我正在通过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 registrati
$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的任何模式
referenceid
和keyid
字段都是VARCHAR(100)
。您正在执行的update语句执行布尔运算。我不喜欢mysql中的这种行为
当前update语句如下所示:
UPDATE tableName SET col1 = 2 AND col2 = 3
而MySQL
server不会抛出任何异常,因为语法是允许的,它将其读取为:
UPDATE tableName SET col1 = (2 AND (col2 = 3))
如果要更新多个列,请使用,
将列与分开
UPDATE registrations
SET referenceid = "4469731",
action = "newregistration", .....
正在执行的update语句执行布尔运算。我不喜欢mysql中的这种行为
当前update语句如下所示:
UPDATE tableName SET col1 = 2 AND col2 = 3
而MySQL
server不会抛出任何异常,因为语法是允许的,它将其读取为:
UPDATE tableName SET col1 = (2 AND (col2 = 3))
如果要更新多个列,请使用,
将列与分开
UPDATE registrations
SET referenceid = "4469731",
action = "newregistration", .....
更新时,不使用and而不是逗号添加列,因此更新应如下所示:
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"
更新时,不使用and而不是逗号添加列,因此更新应如下所示:
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"
这是您正在执行的完整update语句吗?包含查询的php代码是什么?请尝试逗号而不是,并将和替换为,
谢谢,Waygood。这解决了问题。在回答J W下面的回答后,我看到了您的评论。这是您正在执行的完整更新语句吗?包含查询的php代码是什么?请尝试逗号而不是,并用替换和s,
谢谢,Waygood。这解决了问题。我在回复J W下面的答案后看到了你的评论。谢谢!导致我原来问题的逻辑缺陷现在清楚多了。谢谢!导致我最初问题的逻辑缺陷现在更清楚了。