Php quotation marks on mysysql data

Source: Internet
Author: User
The question about the mysysql data input quotation marks in php is generally returned after mysql Query: echo $ rs ['id']; or echo $ rs ["id"]; or echo $ rs [id]; are there any differences between the three ?, The first two can be used. Generally, the first (habit) and the third type of writing usually have the question of Notice: Useofund php inputting quotation marks on mysysql data.
After the mysql Query is complete, the output is echo $ rs ['id']; echo $ rs ["id"]; or echo $ rs [id]; are there any differences between the three?

------ Solution --------------------
The first two can be used. generally, writing is the first one (habit)
The third type usually has the Notice: Use of undefined constant id warning unless you lower the error check level

------ Solution --------------------
There must be no difference between the three, but the difference is the efficiency of their operation.
In comparison, $ rs [id] is less efficient. In addition, echo $ rs ["id"] and then echo $ rs ['id']
So try to use single quotes during development.
------ Solution --------------------
When double quotation marks are used to enclose strings, the PHP interpreter will replace and escape the variables, such as "", even if there is no variable in the quotation marks, the PHP interpreter will still check it. Therefore, if you only want to output a basic string, use single quotes to save some resources. Of course, if you need to replace the variable, you must use double quotation marks, but in other cases, you should still use single quotation marks.
The third is the incorrect syntax.

------ Solution --------------------
In php5, $ rs [id] prompts a warning message, as if it has been disabled in php6.
Echo $ rs ['id'] is slightly different from echo $ rs ["id, however, some people say that echo $ rs ['id'] is more efficient than echo $ rs ["id"], but this is a rumor.

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.