MySQL 错误 - SQLSTATE [42000]:语法错误或访问冲突:1064

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9474576/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:18:05  来源:igfitidea点击:

MySQL Error - SQLSTATE [42000]: Syntax error or access violation: 1064

mysqlpdofuelphp

提问by Ashley Bye

I've looked through the suggested code and cannot find an answer that fixes the problem so I am asking away.

我查看了建议的代码,但找不到解决问题的答案,所以我问了。

I am using MAMP v2.0.5, MySQL v5.5.9, PHP v5.3.6 (according to MAMP, v5.3.8 according to OS X) and FuelPHP v1.1, and being new to frameworks I am working through a tutorial. Part of the tutorial requires the use of 'oil' to carry out migrations to update the project. Having defined a table, the migration applies the SQL to generate the table. When I do so, I get the above error. Having looked through the generated code I can't find any errors (maybe I am missing something obvious). I am using PDO and have also checked that my sql_mode = '', which it does. Running a MySQL query from the command line and phpMyAdmin confirms this. I think this is a MySQL error and not a problem with FuelPHP/oil. Does anybody have any suggestions?

我正在使用 MAMP v2.0.5、MySQL v5.5.9、PHP v5.3.6(根据 MA​​MP,根据 OS X v5.3.8)和 FuelPHP v1.1,并且是我正在学习教程的框架的新手。本教程的一部分需要使用“油”来执行迁移以更新项目。定义表后,迁移应用 SQL 来生成表。当我这样做时,我收到上述错误。查看了生成的代码后,我找不到任何错误(也许我遗漏了一些明显的东西)。我正在使用 PDO 并且还检查了 my sql_mode = '',它确实如此。从命令行运行 MySQL 查询,phpMyAdmin 确认了这一点。我认为这是一个 MySQL 错误,而不是 FuelPHP/oil 的问题。有人有什么建议吗?

The generated SQL:

生成的 SQL:

CREATE TABLE IF NOT EXISTS `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NULL,
    `email` varchar(255) NOT NULL,
    `last_login` int(11) NOT NULL,
    `login_hash` varchar(255) NOT NULL,
    `profile_fields` text NOT NULL,
    `created_at` int(11) NOT NULL,
    `updated_at` int(11) NOT NULL,
    PRIMARY KEY `id` (`id`)
) DEFAULT CHARACTER SET utf8;

The error:

错误:

    bash:blog me$ oil refine migrate
Error - SQLSTATE[42000]: Syntax error or access violation: 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 'varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NU' at line 3 with query: "CREATE TABLE IF NOT EXISTS `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NULL,
    `email` varchar(255) NOT NULL,
    `last_login` int(11) NOT NULL,
    `login_hash` varchar(255) NOT NULL,
    `profile_fields` text NOT NULL,
    `created_at` int(11) NOT NULL,
    `updated_at` int(11) NOT NULL,
    PRIMARY KEY `id` (`id`)
) DEFAULT CHARACTER SET utf8;" in COREPATH/classes/database/pdo/connection.php on line 137

回答by guido

You made a typo:

你打错了:

`username` varhcar(50) NOT NULL,

should be:

应该:

`username` varchar(50) NOT NULL,