如何将嵌套 sql 查询转换为 zend 1.12 格式

How to convert nested sql query to zend 1.12 format

我的查询:

select distinct ml.send_to from message_log as ml where NOT exists
(select mobile_no from user_details WHERE user_details.mobile_no = ml.send_to);

您可以在 zend 中使用客户查询

$sql = 'select distinct ml.send_to from message_log as ml where NOT exists
(select mobile_no from user_details WHERE user_details.mobile_no = ml.send_to);';

 $stmt = new Zend_Db_Statement_Mysqli($db, $sql);
 $stmt->execute();
 while ($row = $stmt->fetch()) {
   echo $row['send_to'];
 }

这对你很有帮助

http://framework.zend.com/manual/1.12/en/zend.db.statement.html

$select1 = $db->select()->from('user_details',array('mobile_no'))
                  ->where('user_details.mobile_no = ml.send_to');

$select2 = $db->select()->distinct()
               ->from(array('ml'=>'message_log'), array('ml.send_to')))
               ->where('NOT EXISTS ?', $select1);

这是最简单的方法。