Php 创建表SQL语句赢得';跑不动
当我尝试运行此语句时:Php 创建表SQL语句赢得';跑不动,php,mysql,Php,Mysql,当我尝试运行此语句时: CREATE TABLE 'score_table' ( 'name' text NOT NULL, 'email' text NOT NULL, 'company' text NOT NULL, 'score_total' bigint(11) NOT NULL, 'score_string' longtext NOT NULL, 'id' int(11) NOT NULL auto_increment, 'date' time
CREATE TABLE 'score_table'
(
'name' text NOT NULL,
'email' text NOT NULL,
'company' text NOT NULL,
'score_total' bigint(11) NOT NULL,
'score_string' longtext NOT NULL,
'id' int(11) NOT NULL auto_increment,
'date' timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY ('id')
)
ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
我得到这个错误:
#1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near ''score_table'
('name' text NOT NULL, 'email' text NOT NULL, 'company' text NOT N' at line 1
我不知道出了什么问题,任何帮助都将不胜感激 表名和字段名需要放在反勾号中,而不是单引号(或根本没有引号):
您不应该像这样用单引号括起表名
CREATE TABLE `score_table` (`name` text NOT NULL, `email` text NOT NULL, `company` text NOT NULL, `score_total` bigint(11) NOT NULL, `score_string` longtext NOT NULL, `id` int(11) NOT NULL auto_increment, `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
使用反勾号而不是单引号: 您的SQL语句应该是:
CREATE TABLE score_table (
`name` text NOT NULL,
`email` text NOT NULL,
`company` text NOT NULL,
`score_total` bigint(11) NOT NULL,
`score_string` longtext NOT NULL,
`id` int(11) NOT NULL auto_increment,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
ENGINE= MyISAM DEFAULT CHARSET=latin1;
如前所述,表名和字段名不能用引号括起来,因此请避免使用引号。我编辑了您的查询,请尝试此操作,如果您使用的是魔术引号,也请避免使用它们(请在当前场景中避免使用魔术引号,以确定您的操作是否正确)
给出了足够的答案,所以我想说一句:你真的过度使用了引号。您不必使用它们,除非名称同时兼作关键字。看:哇!谢谢大家的回复!堆栈溢出为王;)
CREATE TABLE score_table (
`name` text NOT NULL,
`email` text NOT NULL,
`company` text NOT NULL,
`score_total` bigint(11) NOT NULL,
`score_string` longtext NOT NULL,
`id` int(11) NOT NULL auto_increment,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
ENGINE= MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE score_table (name text NOT NULL, email text NOT NULL, company text NOT NULL, score_total bigint(11) NOT NULL, score_string longtext NOT NULL, id int(11) NOT NULL auto_increment, date timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (id) ) ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;