The PHP ADO Access database UPDATE statement cannot reference the value of the primary key

Source: Internet
Author: User
Note No is a primary key in the Access table

I want to change the ID of no=290 to 11, and the following two sentences do not change after execution
$query = "Update sensors set id=11 where no=290";
$result = $conn->execute ($query);
-----------------------------------------------
But the following two sentences are effective after execution, can change the record ID of type=49 to 11
$query = "Update sensors set id=11 where type=49";
$result = $conn->execute ($query);
------------------------------------------------

Want to know why the value of the reference primary key is not possible?


Reply to discussion (solution)

Try this:
Update sensors set id=11 where no=290 and type=49

is not the primary key repeated ~

Try this:
Update sensors set id=11 where no=290 and type=49

is not the primary key repeated ~

The primary key system automatically increases, is unique, cannot have the duplicate value
My following sentence is OK, (XXXXXX is the specific need to update the field)
Update sensors set XXXXXXXX where id=15 and type=48 and Prop=0


Try this:
Update sensors set id=11 where no=290 and type=49

is not the primary key repeated ~

The primary key system automatically increases, is unique, cannot have the duplicate value
My following sentence is OK, (XXXXXX is the specific need to update the field)
Update sensors set XXXXXXXX where id=15 and type=48 and Prop=0


SELECT * from sensors where no=290 see

To help you go to the PHP area, is not the Type field is a character, change it to try

Update sensors set id=11 where type= ' 49 '

No is a reserved word for access (see http://office.microsoft.com/zh-cn/access-help/HA010030643.aspx)
Reserved words to avoid when selecting an identifier name
If it is already used and is inconvenient to modify, it should be escaped: enclosed in brackets

$query = "Update sensors set id=11 where [no]=290";

No is a reserved word for access (see http://office.microsoft.com/zh-cn/access-help/HA010030643.aspx)
Reserved words to avoid when selecting an identifier name
If it is already used and is inconvenient to modify, it should be escaped: enclosed in brackets

$query = "Update sensors set id=11 where [no]=290";

Test, indeed, as the upstairs said no is reserved word, it is wrapped in square brackets to get the correct results, thank you, knot to points! ~

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.