MySQL-what are the points and double quotes before and after variables in the following PHP database INSERT statements?

Source: Internet
Author: User
Tags php database
 $query = "insert into books values        ('".$isbn."', '".$author."', '".$title."', '".$price."')";

Reply content:

 $query = "insert into books values        ('".$isbn."', '".$author."', '".$title."', '".$price."')";

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

  • 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.