使用 Doctrine 保存行时出现 Doctrine_Connection_Mysql_Exception
我有一张简单的桌子。这是模型图片:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用标识符引用;
http://www.doctrine-project.org/documentation /manual/1_2/hu/configuration#identifier-quoting
use identifier quoting;
http://www.doctrine-project.org/documentation/manual/1_2/hu/configuration#identifier-quoting
似乎 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).