A
A
andruxin2013-12-09 12:40:04
Yii
andruxin, 2013-12-09 12:40:04

Yii + ADODB(Access). Any recipes?

I need to attach an Access database to the site, I know how to work with it in native PHP, but I didn’t find examples of how to work with a database from Yii. Has anyone had crossbreeding experience?
The database is working, therefore it is impossible to convert it to mysql.
here is a native example.

$cnn = new COM("ADODB.Connection",null,CP_UTF8) or die("Cannot start ADO");
$cnn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db.mdb;Persist Security Info=False");
$rs = $cnn->Execute("select * from table");

while(!$rs->EOF){
  $dt = $rs->Fields["date"]->Value;
  echo $dt;
  $rs->MoveNext();
}
$rs=$cnn=null;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vit, 2013-12-09
@fornit1917

Yii works with the database through PDO. In PDO, there seems to be ODBC support, through which, in theory, you can work with Access.
Here is an example connection string:
Something similar should be written in the Yii config for db.

A
andruxin, 2013-12-09
@andruxin

The only thing I could get to.
in main.php

'db'=>array(
  'class'=>'CDbConnection',
  'connectionString' => 'odbc:DRIVER={Microsoft Access Driver (*.mdb)};Dbq=d:\\db.mdb;',
  'username'=>'',
  'password'=>'',
        ),

$res=Yii::app()->db->createCommand('select * from table');
  $rows=$res->queryAll();
  foreach($rows as $row) {
    print_r($row);
  }

No AR models are out of the question. It turns out here it will be necessary only pens.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question