|
|||
|
Zend_Db_Table already allows you to make joins.
Code:
<?php
$table = new Bugs();
$select = $table->select()->setIntegrityCheck(false);
$select->where('bug_status = ?', 'NEW')
->join('accounts', 'accounts.account_id = bugs.reported_by', 'account_name')
->where('accounts.account_name = ?', 'Bob');
$rows = $table->fetchAll($select);
|
|
|||
|
Quote:
PHP Code:
|
|
||||
|
Quote:
Example: Code:
"SELECT * FROM table_1 LEFT JOIN table_2 ON table_1.table_2_id = table_2.id WHERE id = '123'" |
|
||||
|
The methods to create your queries are more convenience functions and to give you a standard interface so that changes in syntax per DB Brand can be normalized and make your app more portable, if you wanted to say, switch from MySQL to Oracle.
However, since no DB is going to let you get away with amigious column names, such as what you described, the onnus is on the developer to pass the table name with the column name when getting into situations where the field could be ambigious, which with the ZF is going to be through the fetch* style, and not find. Find is only for single table look ups by primary key... in other words not for joined tables and other complex queries. |
|
||||
|
Yeah, I get that... but why not add the table name into the query? What's the catch? Why not?
Sometimes you create an app and u want to make it slightly more complex and a join can add valuable data in a rather seemless way. This would enable that functionality in a fast and easy way that's very cost-effective. |
|
|||
|
Thanks. I have done that already. But what i want is, how to display MYSQL ERRORS.? While getting error, ZF send the page to Its error.phtml page and calles the Error controller automatically. So, i could not able to find the mysql error and to debug it.
-- Mugesh |
|
||||
|
@mugesh
Which errors are you looking for? Connection issues can be caught and displayed with a try/catch block around that code (we do it in our bootstrap). As for other DB errors, if you catch the right Exception object (Zend_DB_Exception, etc) you should be able to get the right error. Zend_Exception should be your last (default) catch block, so that general/other errors can be caught at that point. HTH, -e |
![]() |
| Thread Tools | |
| Display Modes | |
|
|