Home > Backend Development > PHP Tutorial > PHP里面如何按时间创建MySQL数据库

PHP里面如何按时间创建MySQL数据库

WBOY
Release: 2016-06-13 11:17:34
Original
1020 people have browsed it

PHP里面怎么按时间创建MySQL数据库?

本帖最后由 UniverseOS 于 2013-03-17 11:34:14 编辑 我目前有一个需求,按月份(也就是date('Ym'))创建数据库,我目前的SQL语句:
$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)";
Copy after login

如果把time赋值time=date('Ym')会报错滴(SQL语法不正确),怎么写才正确?

------解决方案--------------------
$dbtime = date('Ym');
$sql = "CREATE TABLE IF NOT EXISTS `$dbtime` ( .... ";

其实你前面加一个字符不就简单明了了?
$dbtime = 't' . date('Ym');
$sql = "CREATE TABLE IF NOT EXISTS $dbtime ( .... ";
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template