简体   繁体   中英

Translating this sql statement to Zend_Db_Table

I have this test query that works fine:

select `name` from `Role` as rl, `UserRole` as ur 
WHERE rl.id = ur.roleId AND ur.userId = '1'

result: 'test'

I 'm trying to use Zend_Table to do the same thing but I seem to be doing it wrong. Here 's what I 'm at:

$usrRole = new Schema_UserRole(array ('db' => $db));
$role = new Schema_Role(array ('db' => $db));
$select = $role->select();
$select
    ->setIntegrityCheck(false)
    ->from(array ('rl' => $role))
    ->join(array ('ur' => $usrRole), 'rl.id = ur.roleId')
    ->where('ur.userId = ?', '1');
$rowset = $role->fetchRow($select);
$out = $rowset->toArray();

Result: ''

Thanks!

I found it, it seems it needs a string on the first parameter of join .

$select
    ->setIntegrityCheck(false)
    ->from($role, array('name'))
    ->joinLeft('UserRole', 'Role.id = UserRole.roleId', '')
    ->where('UserRole.userId = ?', '1');

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.

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