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.