phalcon Database Management Using standard SQL directly with models

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

To use SQL syntax with model, that would transfer result to proper instantions, you should use directly one of Phalcon\Mvc\Model\Resultset classes:

$users = new \Application\Models\Users();

// bitwise operation on `flag` field
$sql = 'SELECT * FROM phorum.users WHERE
        (15 & (1 << (flag - 1))) > 0  ORDER BY login DESC';

// as a result you will have a Resultset\Simple with Models\Users instances.
$result = new \Phalcon\Mvc\Model\Resultset\Simple(
    null,

    // what model to use for data returned from SQL
    $users,

    // setting result via "read connection" proper for this model.
    $users->getReadConnection()->query($sql) 
);


Got any phalcon Question?