In PHP, how does one create a MySQL database by time?

Source: Internet
Author: User
In PHP, how does one create a MySQL database by time? I currently have a requirement to create a database by month (that is, date ('ym'). my current SQL statement:
$sql = "CREATE TABLE IF NOT EXISTS time (file_id int(10) auto_increment primary key,filename varchar(60),filepath varchar(60),filesize int(10),uploadtime date)";

If you assign time = date ('ym'), an error is reported (the SQL syntax is incorrect). how can this problem be solved?


Reply to discussion (solution)

MySQL generally requires that the table name and field name comply with the variable naming rules.
Start with a letter or underline, followed by a combination of letters, numbers, and underscores
For names that do not comply with the naming rules of variables or mysql reserved words that do not comply with the naming rules, you need to use the escape character 'to enclose it
Create table if not exists '123 '(....
You can.

MySQL generally requires that the table name and field name comply with the variable naming rules.
Start with a letter or underline, followed by a combination of letters, numbers, and underscores
For names that do not comply with the naming rules of variables or mysql reserved words that do not comply with the naming rules, you need to use the escape character 'to enclose it
Create table if not exists '123 '(....
You can.
How to escape variables? For example, if $ dbtime = date ('ym') and the database name is $ dbtime, how can I write a statement?

What do you want?

What do you want?
Create a database by month. for example, if the database is in July, create a data table named 201303 in a database (if it does not exist). create a data table named 201304 in July, and so on. Now I want to know how to write this SQL statement correctly.

$ Dbtime = date ('ym ');
$ SQL = "CREATE TABLE IF NOT EXISTS '$ dbtime '(....";

In fact, it's easy to add a character before you?
$ Dbtime = 't'. date ('ym ');
$ SQL = "CREATE TABLE IF NOT EXISTS $ dbtime (....";

$ Dbtime = date ('ym ');
$ SQL = "CREATE TABLE IF NOT EXISTS '$ dbtime '(....";

In fact, it's easy to add a character before you?
$ Dbtime = 't'. date ('ym ');
$ SQL = "CREATE TABLE IF NOT EXISTS $ dbtime (....";
This method works, and I will try to remove the above t.

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.