使用 Doctrine 保存行时出现 Doctrine_Connection_Mysql_Exception

发布于 2024-11-28 11:27:05 字数 3196 浏览 1 评论 0原文

我有一张简单的桌子。这是模型图片:

abstract class BaseImages extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('images');
        $this->hasColumn('id', 'integer', 4, array(
             'type' => 'integer',
             'length' => 4,
             'fixed' => false,
             'unsigned' => false,
             'primary' => true,
             'autoincrement' => true,
             ));
        $this->hasColumn('file', 'string', 45, array(
             'type' => 'string',
             'length' => 45,
             'fixed' => false,
             'unsigned' => false,
             'primary' => false,
             'notnull' => false,
             'autoincrement' => false,
             ));
        $this->hasColumn('order', 'integer', 4, array(
             'type' => 'integer',
             'length' => 4,
             'fixed' => false,
             'unsigned' => false,
             'primary' => false,
             'default' => '0',
             'notnull' => false,
             'autoincrement' => false,
             ));
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasMany('AuthorsHasImages', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('Banners', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('BooksHasImages', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('Collections', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('IllustratorsHasImages', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('MerchandisingHasImages', array(
             'local' => 'id',
             'foreign' => 'images_id'));
    }
}

当我使用时:

$image = new Images();
$image->file = $name;
$image->save();

我有以下错误:

致命错误:未捕获异常“Doctrine_Connection_Mysql_Exception”,消息为“SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 /Users/maurogadaleta/Sites/org.blackiebooks 中第 1 行的 'order, file) VALUES ('0', 'P8040001.JPG')' 附近使用的正确语法/phpinc/doctrine/Doctrine/Connection.php:1082 堆栈跟踪:#0 /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection/Statement.php(269): Doctrine_Connection->rethrowException(Object(PDOException), Object(Doctrine_Connection_Statement)) #1 /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection.php(1042): Doctrine_Connection_Statement->execute(Array) #2 /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine /连接.php(687): Doctrine_Connection->exec('INSERT INTO ima...', Array) #3 /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection/UnitOfWork.php(647): Doctrine_ in /Users/ maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection.php 在线1082

有谁知道为什么我会收到此错误以及如何解决该问题?

I have a simple table. This is the model Images:

abstract class BaseImages extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('images');
        $this->hasColumn('id', 'integer', 4, array(
             'type' => 'integer',
             'length' => 4,
             'fixed' => false,
             'unsigned' => false,
             'primary' => true,
             'autoincrement' => true,
             ));
        $this->hasColumn('file', 'string', 45, array(
             'type' => 'string',
             'length' => 45,
             'fixed' => false,
             'unsigned' => false,
             'primary' => false,
             'notnull' => false,
             'autoincrement' => false,
             ));
        $this->hasColumn('order', 'integer', 4, array(
             'type' => 'integer',
             'length' => 4,
             'fixed' => false,
             'unsigned' => false,
             'primary' => false,
             'default' => '0',
             'notnull' => false,
             'autoincrement' => false,
             ));
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasMany('AuthorsHasImages', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('Banners', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('BooksHasImages', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('Collections', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('IllustratorsHasImages', array(
             'local' => 'id',
             'foreign' => 'images_id'));

        $this->hasMany('MerchandisingHasImages', array(
             'local' => 'id',
             'foreign' => 'images_id'));
    }
}

When I use:

$image = new Images();
$image->file = $name;
$image->save();

I have the following error:

Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message '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 'order, file) VALUES ('0', 'P8040001.JPG')' at line 1' in /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection.php:1082 Stack trace: #0 /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection/Statement.php(269): Doctrine_Connection->rethrowException(Object(PDOException), Object(Doctrine_Connection_Statement)) #1 /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection.php(1042): Doctrine_Connection_Statement->execute(Array) #2 /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection.php(687): Doctrine_Connection->exec('INSERT INTO ima...', Array) #3 /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection/UnitOfWork.php(647): Doctrine_ in /Users/maurogadaleta/Sites/org.blackiebooks/phpinc/doctrine/Doctrine/Connection.php on line 1082

Does anyone know why I get this error and what I can do to fix the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木有鱼丸 2024-12-05 11:27:05

使用标识符引用;

$conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);

http://www.doctrine-project.org/documentation /manual/1_2/hu/configuration#identifier-quoting

use identifier quoting;

$conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);

http://www.doctrine-project.org/documentation/manual/1_2/hu/configuration#identifier-quoting

待天淡蓝洁白时 2024-12-05 11:27:05

似乎 Doctrine 没有引用列名,而 order 是 MySQL 关键字。尝试重命名该列(或者如果可能的话强制 Doctrine 引用它)。

Seems like Doctrine doesn't quote column names and order is a MySQL keyword. Try renaming the column (or forcing Doctrine to quote it if that is possible).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文