Yii Framework Forum: Yii ODBC - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Yii ODBC Rate Topic: -----

#1 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 15 November 2009 - 11:39 PM

Hi,

Does someone have an example of connecting to .mdb via ODBC from Yii?

Thanks a lot.

Daniel
0

#2 User is offline   killermonk 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 27-July 09

Posted 16 November 2009 - 01:21 AM

The Yii framework uses PDO. As such, anything supported by PDO is supported by Yii. All you should have to change to make it connect to a new datasource is your connect string.

To connect to a .mdb database, you will want to use something like this for your connection string

"odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\accounts.mdb;Uid=Admin"


I'm not sure all the options you will need, but that should get your basic connection working.

I got this information from http://www.phpro.org...HP-PDO.html#4.7, so I don't know much else about it. If you can get all the options for your .mdb file working properly, though, it should connect to the database without any problems. As far as I know.
0

#3 User is offline   Samy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-January 10
  • Location:Belgium

Posted 19 January 2010 - 09:37 AM

I have the same problem.

I'm trying to use odbc, and entered

'db'=>array('connectionString'=>"odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\devl\jewel\jewel_be.mdb;Uid=Admin"),

into config/main.php, but it doesn't work.
When I try to use the model instruction in the shell, I get an error. More precisely, the createPDOInstance() method returns the error.

I can use the same connectionstring when I use PDO directly, so it seems to be a Yii-issue.

Can anyone enlighten me?

Thanks
0

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 19 January 2010 - 09:49 AM

What error do you get? I think at least the PDO object should get generated. But that's not enough to use AR with ODBC. You'll also need the according classes for schema handling (framework/db/ar/schema). There's no implementation for ODBC (yet). Maybe give it a try? ;)
0

#5 User is offline   Samy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-January 10
  • Location:Belgium

Posted 20 January 2010 - 03:38 AM

View PostMike, on 19 January 2010 - 09:49 AM, said:

What error do you get? I think at least the PDO object should get generated. But that's not enough to use AR with ODBC. You'll also need the according classes for schema handling (framework/db/ar/schema). There's no implementation for ODBC (yet). Maybe give it a try? ;)
Thanks.

These are the error messages I get when I try the model table command in yiic shell:

exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in C:\wamp\yii\framework\db\CDbConnection.php:267
Stack trace:
#0 C:\wamp\yii\framework\db\CDbConnection.php(237): CDbConnection->open()
#1 C:\wamp\yii\framework\db\CDbConnection.php(216): CDbConnection->setActive(true)
#2 C:\wamp\yii\framework\base\CModule.php(357): CDbConnection->init()
#3 C:\wamp\yii\framework\base\CApplication.php(391): CModule->getComponent('db')

#4 C:\wamp\yii\framework\cli\commands\shell\ModelCommand.php(260): CApplication->getDb()
#5 C:\wamp\yii\framework\cli\commands\ShellCommand.php(144): ModelCommand->run(Array)
#6 C:\wamp\yii\framework\cli\commands\ShellCommand.php(99): ShellCommand->runShell()
#7 C:\wamp\yii\framework\console\CConsoleCommandRunner.php(62): ShellCommand->run(Array)
#8 C:\wamp\yii\framework\console\CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)
#9 C:\wamp\yii\framework\base\CApplication.php(135): CConsoleApplication->processRequest()
#10 C:\wamp\yii\framework\yiic.php(31): CApplication->run()
#11 C:\wamp\yii\framework\yiic(15): require_once('C:\wamp\yii\fra...')
#12 {main}

But OK, since odbc is not yet implemented, I will have to reassess the options.
It is a little early for me in Yii to implement it myself. ;)
0

#6 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 20 January 2010 - 03:57 AM

View PostSamy, on 20 January 2010 - 03:38 AM, said:

But OK, since odbc is not yet implemented, I will have to reassess the options.
It is a little early for me in Yii to implement it myself. ;)


I see. :) Take your time, it might not be as hard as you think. You could take the classes framework/db/schemas/mysql as template. But i might be wrong: Didn't look too deep into that part of the implementation yet.

From your error message i'd say: You are missing the PDO ODBC driver in you PHP installation. They are crucial to work with ODBC at all.
0

#7 User is offline   Samy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-January 10
  • Location:Belgium

Posted 23 January 2010 - 04:11 AM

View PostMike, on 20 January 2010 - 03:57 AM, said:

I see. :) Take your time, it might not be as hard as you think. You could take the classes framework/db/schemas/mysql as template. But i might be wrong: Didn't look too deep into that part of the implementation yet.
Maybe I'll try it.

Bu given that is has not yet been done, I fear it won't be that easy



View PostMike, on 20 January 2010 - 03:57 AM, said:

From your error message i'd say: You are missing the PDO ODBC driver in you PHP installation. They are crucial to work with ODBC at all.
PDO works fine when I use it in my regular php code.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users