如何调试MySQL/Doctrine2查询?
2022-08-30 15:22:19
我正在将MySQL与Zend Framework & Doctrine 2一起使用。我认为即使你不使用教义2,你也会熟悉这样的错误。
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 'ASC' at line 1
问题是我没有看到完整的查询。如果没有ORM框架,我可能可以很容易地回显sql,但是有了框架,我怎么能找出它试图执行的SQL呢?我将误差缩小到
$progress = $task->getProgress();
$progress
已声明
// Application\Models\Task
/**
* @OneToMany(targetEntity="TaskProgress", mappedBy="task")
* @OrderBy({"seq" = "ASC"})
*/
protected $progress;
在MySQL中,任务类看起来像
CREATE TABLE `tasks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_id` int(11) DEFAULT NULL,
`assigned_id` int(11) DEFAULT NULL,
`list_id` int(11) DEFAULT NULL,
`name` varchar(60) NOT NULL,
`seq` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `tasks_owner_id_idx` (`owner_id`),
KEY `tasks_assigned_id_idx` (`assigned_id`),
KEY `tasks_list_id_idx` (`list_id`),
CONSTRAINT `tasks_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`),
CONSTRAINT `tasks_ibfk_2` FOREIGN KEY (`assigned_id`) REFERENCES `users` (`id`),
CONSTRAINT `tasks_ibfk_3` FOREIGN KEY (`list_id`) REFERENCES `lists` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1$$