Php Mysql选择查询不起作用

时间:2015-05-11 17:35:26

标签: php mysql zend-framework zend-framework2

以下查询会导致以下错误:

  

SQLSTATE [23000]:违反完整性约束:1052列' AccountId' in where子句不明确

$select = $this->select()
            ->from(array('finance_account' => DB_TABLE_PREFIX . 'finance_account'), array(
                    'AccountId',
                    'ParentAccountId',
                    'AccountGroupId',
                    'AccountPath',
                    'AccountCode',
                    'AccountName',
                    'Description'
                ))
            ->joinLeft(array('ac' => DB_TABLE_PREFIX . 'customer'), 'finance_account.AccountId = ac.AccountId', array())
                    // using "array_unique()" to minimize db overhead
             ->where('AccountId IN (?)', array_unique($parentIds))
            ->setIntegrityCheck(false);

我没有任何其他专栏可以加入。我现在该怎么办?

1 个答案:

答案 0 :(得分:1)

AccountId就像finance_account.AccountId或ac.AccountId一样,因为查询在哪个表上看起来不明确

$ select = $ this-> select()              - > from(array('finance_account'=> DB_TABLE_PREFIX。'finance_account'),array(                     '帐户ID',                     'ParentAccountId',                     'AccountGroupId',                     'AccountPath',                     'AccountCode',                     '用户名',                     '描述'                 ))              - > joinLeft(array('ac'=> DB_TABLE_PREFIX。'customer'),'finance_account.AccountId = ac.AccountId',array())                     //使用“array_unique()”来最小化数据库开销               - > where('ac.AccountId IN(?)',array_unique($ parentIds))              - > setIntegrityCheck(假);