MySQL 服务器版本,用于在 '('id') 附近使用正确的语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16607439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL server version for the right syntax to use near '('id')
提问by steve
i get this error when i try to inport to data base
当我尝试导入数据库时出现此错误
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 '('id') ) TYPE=MyISAM AUTO_INCREMENT=6' at line 4
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 4 行的 '('id') ) TYPE=MyISAM AUTO_INCREMENT=6' 附近使用的正确语法
DROP TABLE IF EXISTS `categories`;
CREATE TABLE `categories` (
`id` int(5) NOT NULL auto_increment,
`category` varchar(50) NOT NULL default '',
PRIMARY KEY ('id')
) TYPE=MyISAM AUTO_INCREMENT=6 ;
回答by Taryn
You have two issues with the code, remove the single quotes around the id
in the primary key declaration. You can use backticks or nothing.
您的代码有两个问题,删除id
主键声明中的单引号。您可以使用反引号或什么都不使用。
And change the Type=MyISAM
to:
并将其更改Type=MyISAM
为:
ENGINE=MyISAM
From the MySQL Docs:
来自MySQL 文档:
The older term TYPE is supported as a synonym for ENGINE for backward compatibility, but ENGINE is the preferred term and TYPE is deprecated.
为了向后兼容,支持旧术语 TYPE 作为 ENGINE 的同义词,但 ENGINE 是首选术语,不推荐使用 TYPE。
So the script will be:
所以脚本将是:
DROP TABLE IF EXISTS `categories`;
CREATE TABLE `categories` (
`id` int(5) NOT NULL auto_increment,
`category` varchar(50) NOT NULL default '',
PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=6 ;
回答by fancyPants
You are using '
here
你在'
这里使用
PRIMARY KEY ('id')
id
is in this case a string, not the column name. Use backticks instead.
id
在这种情况下是一个字符串,而不是列名。改用反引号。
PRIMARY KEY (`id`)
回答by fancyPants
Try this:
尝试这个:
DROP TABLE IF EXISTS `categories`;
CREATE TABLE `categories` (
`id` int(5) NOT NULL auto_increment,
`category` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MYISAM AUTO_INCREMENT=6
The problems is that PRIMARY KEY ('id')
should use backquotes insted of quotes
问题是PRIMARY KEY ('id')
应该使用反引号插入引号
回答by Vojta horvath
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 'FROM disc_disc WHERE disc_id=NULL' at line 1 SQL=SELECT disc_id, disc_name, FROM disc_disc WHERE disc_id=NULL
1064 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“FROM disc_disc WHERE disc_id=NULL”附近使用的正确语法 SQL=SELECT disc_id, disc_name, FROM disc_disc WHERE disc_id=NULL
// zjistit jmeno diskuse
$disc_name = "";
$sql = sprintf("SELECT disc_id, disc_name, " .
"FROM disc_disc " .
"WHERE disc_id=%s",
quote_smart($disc_id));
$db->setQuery($sql);
$rec = $db->loadObjectList();
if ($db->getErrorNum()) {
JError::raiseWarning( 500, $db->stderr() );
}