如何检查 MySQL 查询语法?
我正在开发自己的数据库管理系统,用 PHP 开发,并且我为自己的查询选择了与 MySQL 查询相同的语法。
我想知道是否有一个工具可以检查 MySQL 查询是否有效,而无需连接到真正的 MySQL 数据库。
有人有办法做到吗?我虽然考虑过使用一些正则表达式,但我不确定这是最简单(也是最快)的方法。
I'm working on my own database management system, developped in PHP, and I've chosen the same syntax as the MySQL queries for my own queries.
I'd like to know if there was a tool to check that a MySQL query is valid, without having to connect to a real MySQL database.
Does someone have a way to do it ? I've though about using some regular expressions but I'm not sure this is the easiest (and fastest) way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一些很好的 PHP SQL 解析器可以将查询分解为结构化数组。
您可以通过解析器运行代码并查看它是否中断以确定其语法是否有效。
http://code.google.com/p/php-sql-parser/
和
http://pear.php.net/package/SQL_Parser
是我用过的 2 个在过去。
There's a few good PHP SQL parsers that break down the query into structured arrays.
You could run the code through the parser and see if it breaks to determine whether it's valid syntax.
http://code.google.com/p/php-sql-parser/
and
http://pear.php.net/package/SQL_Parser
are 2 I have used in the past.
像这样的工具不能确保表或列存在。该工具需要数据库模式来检查错误。我使用heidisql,如果我有更多的钱,我会购买在mysql服务器上拥有多个数据库的权利,我会执行“创建数据库”或复制数据库代码并在没有任何值的第二个数据库上进行测试,或者最好有价值观。
a tool like that can't ensure tables or columns exist. the tool needs database schema for checking errors. I use heidisql and If I had more money ı would buy right to have more than one database on mysql server and I would execute the "create database" or copy database code and test on the second database which doesn't have any values, or prefereably, with values.