1

私はphpmysqliを介して次のクエリを実行しています$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の値が継続的に見つかります。このテーブルまたはデータベースに影響を与える他のスクリプトはありません。1ではなく0を配置するパターンを特定できませんでした。

referenceidkeyidフィールドはどちらもVARCHAR(100)'sです。

4

2 に答える 2

3

実行しているupdateステートメントはブール演算を実行します。それは私が好きではないmysqlの振る舞いです。

現在の更新ステートメントは次のようになります。

UPDATE tableName SET col1 = 2 AND col2 = 3

構文が許可されており、次のように読み取られるため、MySQLサーバーは例外をスローしません。

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

複数の列を更新する場合は、を使用,して列を分離しますAND

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

更新するときは、カンマではなく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"
于 2013-03-25T15:03:43.573 に答える