简体   繁体   English

为什么Zend Framework(Zend_Db_table)拒绝这个SQL查询?

[英]Why is Zend Framework (Zend_Db_table) rejecting this SQL Query?

I'm working on a simple JOIN of two tables ( urls and companies ). 我工作的一个简单的JOIN两个表(的urlscompanies )。 I am using this query call: 我正在使用此查询调用:

print $this->_db->select()->from(array('u' => 'urls'),
                                 array('id', 'url', 'company_id'))
                          ->join(array('c' => 'companies'),
                                 'u.company_id = c.id');

which is out putting this query: 这是出于这个问题:

SELECT `u`.`id`, `u`.`url`, `u`.`company_id`, `c`.* FROM `urls` AS `u` INNER JOIN `companies` AS `c` ON u.company_id = c.id

Now, I'd prefer the c.* to not actually appear, but either way it doesn't matter. 现在,我更喜欢c.*实际上没有出现,但无论哪种方式都没关系。 ZF dies with this error: ZF死于这个错误:

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 '' at line 1"

but I can run that query perfectly fine in my MySQL CLI. 但我可以在MySQL CLI中完美地运行该查询。 Any ideas how to fix up this query? 任何想法如何解决这个问题?

I just tried that code in a test script against ZF 1.10 and MySQL 5.1, and it works fine. 我只是在针对ZF 1.10和MySQL 5.1的测试脚本中尝试了该代码,它运行正常。

What user/password are you using to connect to your database? 您使用什么用户/密码连接到数据库? It says "or access violation" so I would test that your db username has the right privileges. 它说“或访问冲突”,所以我会测试你的db用户名是否具有正确的权限。 Try connecting in the MySQL CLI using the exact same user/password and connection method (because privileges can vary depending on the client host, even for the same user/password). 尝试使用完全相同的用户/密码和连接方法在MySQL CLI中进行连接(因为权限可能因客户端主机而异,即使对于相同的用户/密码也是如此)。

See MySQL Zend Framework - SQLSTATE[42000]: Syntax error or access violation: 请参阅MySQL Zend Framework - SQLSTATE [42000]:语法错误或访问冲突:

Btw, you can omit c.* columns by passing an empty array for columns as the third argument to join() : 顺便说一句,您可以通过传递列的空数组作为join()的第三个参数来省略c.*列:

->join(array('c' => 'companies'), 'u.company_id = c.id', array());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM