Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

first argument in constructor of Resultset\Complex - how to built raw SQL

I am trying to build a query using raw SQL. I want the query to be returned as complex Resultset, how to do it?


use use Phalcon\Mvc\Model\Resultset\Complex as Resultset;

$rowSql = 'SELECT
          DISTINCT i.car_id
          FROM cars AS i
          LEFT JOIN
            (some sql..)
          AS e ON (e.car_id = i.car_id)
          WHERE
          i.source_id = 2
          AND e.car IS NULL LIMIT 180;';

$model = new Cars();

$result = new Resultset([
            'HOW THIS ARRAY SHOULD LOOK LIKE?',
        ], $model->getReadConnection()->query($rowSql));

I don't know how first argument of Resultset\Complex constructor should look like? It's array $columnTypes.

TIA!



33.7k
Accepted
answer

You don't have to use Resultset\Complex but Resultset\Simple: https://docs.phalconphp.com/en/latest/reference/phql.html#using-raw-sql