What do you do with double quotes in the PDO of PHP, and why this statement can be executed by

Source: Internet
Author: User
Find a lightweight database class Medoo, feel good, but when used to find a very strange problem
When using MySQL, he assembled SQL table names, field names in double quotation marks, so that the resulting statement cannot be executed directly
Mysql> select * from "Dd_xq_user_info" WHERE "uid" = ' 1 ' and ' status ' = ' 1 ' ORDER by ' id ' LIMIT 1; Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use "" Dd_xq_user_info "WHERE" UID "= ' 1 ' and" status "= ' 1 ' ORDER by" id "LIMIT 1 ' on line 1

However, the execution of this statement with PDO is successful, and there is no error, may I ask what this is all about? What does PDO do?


Reply to discussion (solution)

It's impossible!
Stick out your real code.

Just read through the next Medoo code https://github.com/catfan/Medoo/blob/master/medoo.php
Found executing a statement when connecting to the database
SET sql_mode=ansi_quotes
found that the function of this pattern is to change the double quotation mark to the inverted quotation mark

Ansi_quotes ' "' is treated as the identifier quotation mark (' ' ' quotation mark character), not as the quotation mark character of the string. In ANSI mode, you can still use "' to refer to identifiers. When Ansi_quotes is enabled, you cannot use double quotation marks to reference a string because it is interpreted as a qualifier.

This explains why the above statement can be executed
Can't think of any other problems for the time being.

The default value for Sql_mode is Strict_trans_tables,no_auto_create_user,no_engine_substitution
After the change to ansi_quotes, if there is no other operation, nature will not have an impact

This is the function of MySQL, not the PDO

This is the function of MySQL, not the PDO


Yes, I thought PDO had this function.
By the way I wish the Dragon Boat Festival health, thanks for the holiday also help answer
  • 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.