我正在使用 MySQL 和 Zend Framework &Doctrine 2.我想即使你不使用Doctrine 2,你也会熟悉像
I am using MySQL with Zend Framework & Doctrine 2. I think even if you don't use Doctrine 2, you will be familiar with errors like
SQLSTATE[42000]:语法错误或访问冲突:1064 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的ASC"附近使用的正确语法
问题是我没有看到完整的查询.如果没有 ORM 框架,我可能很容易回显 sql,但是有了框架,我怎么能找出它试图执行的 SQL?我将错误缩小到
The problem is that I don't see the full query. Without an ORM framework, I could probably echo the sql easily, but with a framework, how can I find out what SQL its trying to execute? I narrowed the error down to
$progress = $task->getProgress();
$progress
已声明
// ApplicationModelsTask
/**
* @OneToMany(targetEntity="TaskProgress", mappedBy="task")
* @OrderBy({"seq" = "ASC"})
*/
protected $progress;
在 MySQL 中,任务类看起来像
In MySQL, the task class looks like
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$$
如何使用 mysql 一般查询日志?
一般查询日志是对mysqld正在做什么的一般记录.当客户端连接或断开连接时,服务器将信息写入此日志,并记录从客户端收到的每个 SQL 语句.当您怀疑客户端有错误并想确切知道客户端发送给 mysqld 的内容时,通用查询日志会非常有用.
The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.
这篇关于如何调试 MySQL/Doctrine2 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!