1

我想在 zend 框架 2 中编写如下的 mySQL 查询。

如何在 zend Db 选择约定中转换它?

    SELECT profiles.*, 
    user.email,
    user.first_name,
    user.last_name,
    portfilio_images.profileImage,
    images.url AS imgurl
    FROM profiles

    INNER JOIN user ON user.user_id = profiles.ownerId

    LEFT JOIN (
        SELECT *
        FROM portfilio_images
        WHERE portfilio_images.profileImage = '1'
    ) as portfilio_images ON portfilio_images.profileId = profiles.id

    LEFT JOIN images ON images.id = portfilio_images.imageId

    WHERE profiles.ownerId != '4' AND (profiles.name LIKE '%a%' OR user.first_name LIKE '%a%' OR user.last_name LIKE '%a%')

    GROUP BY user.user_id
4

2 回答 2

1

您还可以使用 Zend\Db\Sql\Select,它允许您以编程方式构建复杂的查询。请参阅此处的文档:

http://zf2.readthedocs.org/en/release-2.1.1/modules/zend.db.sql.html#zend-db-sql-select

于 2013-03-07T10:16:06.417 回答
0

您总是可以只执行原始查询:

$sql = "SELECT * FROM test";

$statement = $abAdapter->query($sql);
$result = $statement->execute();

$resultSet = new ResultSet;
$resultSet->initialize($result);

return $resultSet;

或者如果你想添加一些参数

$sql = "SELECT * FROM test where col = ?";

$statement = $dbAdapter->query($sql);
$result = $statement->execute(array(99));

$resultSet = new ResultSet;
$resultSet->initialize($result);

return $resultSet;
于 2013-03-07T09:13:02.813 回答