No ODBC database schema in Yii?

I’m looking at the source files for Yii 1.1.5, and I don’t see a database schema for odbc. When I use this connection string in my config file:


  'connectionString' => 'odbc:rhinestone',

  'username' => 'user',

  'password' => 'pass',


I get this error:

"CDbConnection does not support reading schema for odbc database."

However, I can use that connection string in regular php and connect just fine:

$dbh= new PDO('odbc:rhinestone', 'user', 'pass');

So I know it’s not an issue with my drivers or with PHP.

Why does Yii not support ODBC? Is this going to change? I’m trying to connect to MSSQL from a linux server and it seems like the pdo mssql and dblib drivers are either experimental or deprecated.

Does anyone have any advice on how to do this?

There is no schema driver for ODBC (framework/db/ar/schema) implemented so you will not be able to Active Record with it. Using query builder is still possible:

$dsn = "odbc:Driver={Microsoft Paradox Driver (*.db )};DriverID=538;Fil=Paradox 5.X;DefaultDir=\\\\Server\\dbfiles\\;Dbq=\\\\Server\\dbfiles\\;CollatingSequence=ASCII;";

$username = '';

$password = '';

$para = new CDbConnection($dsn, $username, $password);

$para->active = true;


$command = $para->createCommand($sql);

$rows = $command->queryAll();

$para->active = false;

If you are using MSSQL you can try connecting with ‘sqlsrv:server=myserver;database=mydb;’,

@samdark, why is it that ODBC doesn’t work with Active Record? Has it just not been implemented in Yii, or is there some inherent problem that makes this difficult or impossible?

If it is not impossible I would greatly appreciate if this were added into the next release. I cannot currently use sqlsrv, mssql, or dblib pdo drivers because they are all either windows-only, deprecated, or experimental as you can see here:

I don’t work with ODBC so I can’t say for sure if there are problems with ODBC + PHP. As for Active Record, it needs schema driver for AR to work. These drivers are located in framework/db/ar/schema. Implementing a driver should not be difficult if you know database well and can test it. If you will implement ODBC schema, we’ll review it and include into 1.1.7.

There’s a PDO driver for ODBC so i think it should be possible to create some AR schema driver for it. On the other hand i also wonder why it hasn’t been implemented yet and if there’s some hindrance. Sometimes this is only because no developer had the oportunity to test the implementation.

So Philip if you give it a try you’ll surely receive lot of Kudos here :)

samdark, am I correct in thinking that if the ODBC is connecting to a DBRM for which Yii does have a schema, you can make it work by adding ‘odbc’ to the $driverMap array of CDbConnection?

For example, if you configure your ODBC that it connects to an external MySQL database, you add ‘odbc’=>‘CMysqlSchema’. Of course, most people would enable external connections to that MySQL database so you can link directly to it using the MySQL PDO driver, but I can imagine there can be usecases where a database can only be connected to using ODBC.

This is just some speculation though. :)

How can we make ActiveRecord odbc connection using dsn . The database is in intersystem cache.