I'm working on a simple JOIN
of two tables ( urls
and companies
). 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. ZF dies with this error:
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. 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.
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. 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).
See MySQL Zend Framework - SQLSTATE[42000]: Syntax error or access violation:
Btw, you can omit c.*
columns by passing an empty array for columns as the third argument to join()
:
->join(array('c' => 'companies'), 'u.company_id = c.id', array());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.