Some of the issues that need to be paid attention to when operating MySQL databases in PHP are very good .. Very novel .. -Database problems
Source: Internet
Author: User
Notes for operating MySQL databases in PHP
1. Semicolon exceptions
For MySQL, the first thing you must remember is that every line of its command is ended with a semicolon (;), ...... There is no such thing as absolute. The same is true here. When a MySQL line is inserted in the PHP code, it is best to omit the semicolon. For example:
Mysql_query ("insert into tablename (first_name, last_name)
VALUES ('$ first_name', '$ last_name ')
");
This is because PHP also ends with a semicolon as a line. The extra semicolon may sometimes make PHP syntax analyzer confused, so it is better to omit it. In this case, although the semicolon is omitted, PHP will automatically add it when executing the MySQL command.
There is also a case where no extra points are required. When you want to display the vertical arrangement of fields, rather than horizontal arrangement as usual, you can use G to end a line of SQL statements, then you will not use a semicolon, for example:
SELECT * from penpals where USER_ID = 1G
2. TEXT, DATE, and SET data types
A field in the MySQL data table must define a data type. There are about 25 options, most of which are straightforward, so there is not much to worry about. But there are a few things to mention.
TEXT is not a data type, although it may be said in some books. It should actually be "long varchar" or "MEDIUMTEXT ".
The format of the DATE data type is YYYY-MM-DD, for example. You can easily use the date function to obtain the current system time in this format:
Date ("Y-m-d ")
In addition, subtraction can be performed between DATA types to obtain the time difference days:
$ Age = ($ current_date-$ birthdate );
SET is a useful data type. It is similar to ENUM, except that SET can save multiple values while ENUM can only save one value. In addition, the SET type can have up to 64 predefined values, while the ENUM type can process up to 65,535 predefined values. What if we need a set with more than 64 values? In this case, you need to define multiple sets to solve this problem together.
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