如何调试MySQL / Doctrine2查询? [英] How to debug MySQL/Doctrine2 Queries?

查看:100
本文介绍了如何调试MySQL / Doctrine2查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL与Zend Framework&原则2.我想即使你不使用教义2,你也会熟悉错误,如


SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在第1行ASC附近使用正确的语法。




问题是我看不到完整的查询。没有ORM框架,我可以很容易地回应sql,但是使用一个框架,我如何找出它试图执行什么SQL?我将错误缩小到

  $ progress = $ task-> getProgress(); 

$ progress 已声明

  // Application\Models\Task 
/ **
* @OneToMany(targetEntity =TaskProgress mapBy =task)
* @OrderBy({seq=ASC})
* /
protected $ progress;

在MySQL中,任务类看起来像

  CREATE TABLE`tasks`(
`id` int(11)NOT NULL AUTO_INCREMENT,
`owner_id` int(11)DEFAULT NULL,
`assign_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`)参考`users`(`id`),
CONSTRAINT`tasks_ibfk_2` FOREIGN KEY(`assigned_id`)参考`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的时候,通用查询日志可能非常有用。



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]: 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

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 is declared

// Application\Models\Task
/**
 * @OneToMany(targetEntity="TaskProgress", mappedBy="task")
 * @OrderBy({"seq" = "ASC"})
 */
protected $progress;

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$$

解决方案

how about using mysql general query log?

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查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆