Try this: Dont use the $table in the from.  Instead..

$table
  ->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
  ->leftJoin($table->getInfo('name'), 'users_id');

This will return the select object with the from part already applied. Also, if you must dynamically get the name, use $table->info().

Hope that helps,
-ralph

WebCorp s.r.o. | Jan Juříček wrote:
Hello,

I'm playling with multiple databases and I want to do a select some data from a table in another schema, that the one currently selected. I have following code

class Users extends Zend_Db_Table{
    protected $_schema = 'ecms3base';
    protected $_name = 'users';
}

$table = new Users();
echo $table->select()->from($table)->joinLeft($table, 'users_id');
exit;

Now there are three use cases I'm trying:

1)      Echo $table->select()->from($table);

a.        SELECT `users`.* FROM `ecms3base`.`users`

2) Echo $table->select()->from($table)->joinLeft('ecms3base.users', 'users_id');

a. SELECT `users`.*, `ecms3base.users_2`.* FROM `ecms3base`.`users` LEFT JOIN `ecms3base`.`users` AS `ecms3base.users_2` ON users_id

3)      Echo $table->select()->from($table)->joinLeft($table, 'users_id');

a.       Resulting in a LOT of errors

i. Warning: preg_match() expects parameter 2 to be string, object given in D:\Web\Lib\Zend\Db\Select.php on line 787

ii. Warning: strrpos() expects parameter 1 to be string, object given in D:\Web\Lib\Zend\Db\Select.php on line 877

iii. Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in D:\Web\Lib\Zend\Db\Select.php on line 880

iv. Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in D:\Web\Lib\Zend\Db\Select.php on line 801

v. Warning: Illegal offset type in D:\Web\Lib\Zend\Db\Select.php on line 809

vi. Warning: Illegal offset type in isset or empty in D:\Web\Lib\Zend\Db\Table\Select.php on line 213

vii. Warning: Select query cannot join with another table in D:\Web\Lib\Zend\Db\Select.php on line 1285

I thought that I should be able to use the $table object directly also in the joinLeft method ... Or shouldn't I?

Thanks in advance

Regards
Jan

/S pozdravem/

*Jan Juříček*
*WebCorp* *s.r.o.*

*Kancelář*: Wichterlova 2372/10, 182 00 Praha
*E-mail*: [email protected] <mailto:[email protected]> *Web*: www.webcorp.cz <http://www.webcorp.cz/>
*Tel.*: (+420) 725 607 671, (+420) 725 607 670

Reply via email to