MySQL single and double quotation marks

Source: Internet
Author: User

Table name, column name best use ' (ESC under that, do not ' error)

This starts with the effect of double quotes and single quotes:
The fields inside the double quotes are interpreted by the compiler and then exported as HTML code, but the single quotes do not need to be interpreted and output directly. For example:
$ABC = ' I love u ';
echo $ABC//result is: I love u
Echo ' $ABC '//Result: $ABC
echo "$ABC"//result is: I love u
So when you assign a value to a SQL statement inside a database, use double quotes inside the sql= "select A,b,c from ..."
But there are single quotes in the SQL statement that enclose the field names
For example: SELECT * FROM table where user= ' abc ';
The SQL statement here can be written directly as sql= "select * from table where user= ' abc '"
But if it looks like the following:
$user = ' abc ';
Sql1= "SELECT * from table where user= '". $user. " "; compare
Sql2= "SELECT * from table where user= ' abc '"
I have added a little space between the single and double quotation marks, and I hope you can see it clearly.
That is, replace ' abc ' with '. $user. ' Are all in a single quotation mark. Just split the entire SQL string.
SQL1 can be decomposed into the following 3 parts
1: "SELECT * from table where user= '"
2: $user
3: "'"
Used between strings. To connect

eg

$sql = ("select * from Myguests where username= $tureusername and password= $turepassword");

$sql = ("select * from myguests where username= '". $tureusername.  "' and password= '". $turepassword. " ‘ " );

The two statements execute the same result, as long as they are understood in PHP. is the link character can be

MySQL single and double quotation marks

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.