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.

Can I bind an array to an IN() condition?: $connection->fetchAll()

Can I bind an array to an IN() condition?

$database = [
        'adapter' => 'Postgresql',
        'host' => 'localhost',
        'username' => 'xerron',
        'password' => 'root',
        'dbname' => 'db_drupal'
    ];

    $adapter = $database['adapter'];
    unset($database['adapter']);

    $class = 'Phalcon\Db\Adapter\Pdo\\' . $adapter;

    $connection = new $class($database);

    $list = false;
    try {
        $names = ['user.role.administrator', 'user.role.anonymous'];
        $sql = 'SELECT name, data FROM config WHERE collection = :collection AND name IN ( :names )';
        $list = $connection->fetchAll(
            $sql,
            \Phalcon\Db::FETCH_ASSOC,
            [
                'collection' => '',
                'names' => implode(',', $names)   // <-- this not work!!!
            ]
        );
        foreach ($list as &$data) {
            $data = unserialize(stream_get_contents($data['data']));
        }
    } catch (\Exception $e) {
        // If we attempt a read without actually having the database or the table
        // available, just return FALSE so the caller can handle it.
    }

    d($list); // kint debug

I found a solution to use this:

SELECT name, data FROM config WHERE collection = :collection AND name IN ( :names[] )