問題描述
我正在使用 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 查詢?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!