Skip to content

Extension to read Microsoft Access Databases (.mdb) in Symfony2

Notifications You must be signed in to change notification settings

TiiToo/PDOAccessBundle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

PDOAccessBundle

Doctrine extension which allows to read Microsoft Access (.mdb) files via Doctrine DBAL in Symfony2.

It uses the PDO_ODBC PHP driver, so I think it could work with any connection, not only MS Access databases. It has been tested only on microsoft Windows XP.

It is not intented for ORM mapping, I've only used to import data from a older Microsoft Access program to Symfony2.

This extension is based on PDODblibBundle

Installation

Configure php.ini in your apache server. Add:

extension=php_pdo_odbc.dll

Then, restart apache2 server

Add the following lines into deps file:

[ClalarcoPDOAccessBundle]
    git=git://github.com/clalarco/PDOAccessBundle.git
    target=/bundles/Clalarco/PDOAccessBundle 
    version=origin/master

Register it in the autoload.php file:

<?php
// app/autoload.php

$loader->registerNamespaces(array(
    'Clalarco'          => __DIR__.'/../vendor/bundles',
));

Now, run the vendors script to download the bundle:

$ php bin/vendors install

Create a connection

** Note: ** You need to separate the default connection in doctrine. Check Symfony2 Doctrine configuration.

The way I created a connection is via config.yml (or config_dev.yml). In windows it works using:

# config.yml

doctrine:
    dbal:
        connections:
            msaccess:
                driver_class: Clalarco\PDOAccessBundle\Doctrine\DBAL\Driver\PDOMdbLib\Driver
                host: "{Microsoft Access Driver (*.mdb)};Dbq=C:\path_to\file.mdb"
                user: Admin
                password: your_password

Replace C:\path_to\file.mdb with your path, and your_password with your password, if any, blank otherwise. 'msaccess' name can also been renamed.

In your controller, add the following lines to get the connection if your connection name is 'msaccess':

<?php

class MyController extends Controller
{
    public function myAction()
    {
        ...
        $conn = $this->get('doctrine.dbal.msaccess_connection');
        ...
        // Once the connection is created, SQL queries are accepted.
        // Check Doctrine DBAL documentation for more information.
        $rows = $conn->fetchAll('SELECT * FROM my_table');
        ...
    }
}

If a the connection is used in a command, the command to get the connection is:

        $conn = $this->getContainer()->get('doctrine')->getConnection('msaccess');

TODO

  • Improve code documentation.

About

Extension to read Microsoft Access Databases (.mdb) in Symfony2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%