We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon Db Connection With Snowflake

Hello,

We have a project that will be using a snowflake database for our data warehouse (https://docs.snowflake.com/en/index.html), is it possible to even connect to this database through a phalcon application (we are currently on an old version of phalcon, 2.0.13, but we will be updating to ~4 soon)?

We were provided https://github.com/snowflakedb/pdo_snowflake as a possible option to connect with pdo, though we like to use the ORM.

edited Jun '20

Phalcon only goes to v4, so I assume you'll be migrating to v4 on PHP v7.

Phalcon uses PDO for its database connectivity, so all you'd need to do is write an adapter class that implements \Phalcon\Db\Adapter\AdapterInterface (https://docs.phalcon.io/4.0/en/api/phalcon_db#db-adapter-adapterinterface), then in your DI, do something like:

$DI->setShared('db',function() use ($Config){
    return new \Namespace\For\Custom\Adapter([/* setup properties like host, dbname, etc */]);
}

You may be able to just use that PDO driver you linked, and use https://docs.phalcon.io/4.0/en/api/phalcon_db#db-adapter-pdo-abstractpdo somehow.

Thank you, I updated my comment to use 4. Used the old 10-key.

Phalcon only goes to v4, so I assume you'll be migrating to v4 on PHP v7.

Phalcon uses PDO for its database connectivity, so all you'd need to do is write an adapter class that implements \Phalcon\Db\Adapter\AdapterInterface (https://docs.phalcon.io/4.0/en/api/phalcon_db#db-adapter-adapterinterface), then in your DI, do something like:

$DI->setShared('db',function() use ($Config){
  return new \Namespace\For\Custom\Adapter([/* setup properties like host, dbname, etc */]);
}

You may be able to just use that PDO driver you linked, and use https://docs.phalcon.io/4.0/en/api/phalcon_db#db-adapter-pdo-abstractpdo somehow.

Thank you for your response, I thought, but was kindof afraid, that was the case. We can try to use the Mysql adapter as a reference but we don't have a lot of experience in Snowflake. I'm assuming we would have to extend Phalcon\Db\Dialect as well with a new Dialect?

Phalcon only goes to v4, so I assume you'll be migrating to v4 on PHP v7.

Phalcon uses PDO for its database connectivity, so all you'd need to do is write an adapter class that implements \Phalcon\Db\Adapter\AdapterInterface (https://docs.phalcon.io/4.0/en/api/phalcon_db#db-adapter-adapterinterface), then in your DI, do something like:

$DI->setShared('db',function() use ($Config){
  return new \Namespace\For\Custom\Adapter([/* setup properties like host, dbname, etc */]);
}

You may be able to just use that PDO driver you linked, and use https://docs.phalcon.io/4.0/en/api/phalcon_db#db-adapter-pdo-abstractpdo somehow.



125.7k
Accepted
answer

I think you'd only need to provide your own dialect if you want PHQL to be able to convert a string before it passes it on to PDO.

The example here: https://docs.phalcon.io/3.4/en/db-layer#database-dialects mentions a custom MATCH_AGAINST function that allows PHQL to convert MATCH_AGAINST to standard SQL. You wouldn't need to do that, though, if you just use statements that the Snowflake PDO adapter is already aware of.

I've never done it, but it seems a custom dialect would only be necessary if you want to provide custom shortcuts you can use in your queries.