Zend Framework gives strange Oracle query
717898Aug 18 2009 — edited Oct 29 2009I'm trying to migrate an application from MySQL to Oracle. I'm a newbie to Oracle.
I want the PHP scripts to work on both MySQL and Oracle.
The query I want to do used to be (for MySQL via AdoDB):
SELECT DISTINCT (id)
FROM table1
INNER JOIN table2 ON table1.id = table2.record_id
AND table2.user_id = "XXX"
AND table1.status = table2.status_id
The following code works great for MySQL but generates some strange output for Oracle:
$db = Zend_Db::factory('Oracle', //Mysqli for the MySQL db connection
array(
'host' => 'hostName',
'dbname' => 'dbName',
'username'=> 'userName',
'password'=> 'userPasswd')
);
$select = $db->select();
$select->distinct();
$select->from(array('i' => 'table1'),array('id'));
$select->joinInner(array('u' => 'table2'),'i.id = u.record_id',array());
$select->where('u.user_id = ?', 'XXX');
$select->where('i.status=u.status_id');
This results in
for MySQL:
SELECT DISTINCT `i`.`id` FROM `table1` AS `i` INNER JOIN `table2` AS `u` ON i.id = u.record_id WHERE (u.user_id = 'XXX') AND (i.status=u.status_id)
this works fine.
for Oracle:
SELECT DISTINCT "i"."id" FROM "table1" "i" INNER JOIN *"table2" "u" ON i.id = u.record_id WHERE (u.user_id = 'XXX') AND (i.status=u.status_id)
this does not work:
ORA-00942: table or view does not exist
when I copy/paste this in SQL developer this gives an error too, complaining about ' *"table2" ' which does not exist.
The only query my SQL developer accepts is :
SELECT DISTINCT i."id" FROM table1 i INNER JOIN table2 u ON i."id" = u."record_id" WHERE (u."user_id" = 'XXX') AND (i."status"=u."status_id")
I have no idea how I can make this query with Zend Framework.
The query should have:
- no quotes around the table names
- quotes around the column names
- no * before the second table name (table2)
Is this a Zend Framework problem or is my Oracle db not very well made?