开发者

Doctrine_Connection_Mysql_Exception when saving a row with Doctrine

开发者 https://www.devze.com 2023-03-26 06:21 出处:网络
I have a simple table.This is the model Images: abstract class BaseImages extends Doctrine_Record { public function setTableDefinition()

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(开发者_如何学C);
$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?


use identifier quoting;

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

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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消