ODBC database in Laravel 4 Interbase

Posted by on in SQL Development

laravel-interbaseBelow I will list the steps to use any ODBC database with our Laravel installed. Sometimes our clients ask us to do a project with a database already established and unusual as might be Firebird or Interbase and the best way to access it is to use ODBC.

First of all we have to download the driver that we will use. In our case we will use Firebird (or InterBase, use it) so we went to the website of FireBird we downloaded and installed.

Now we have to uncomment (to uncomment we remove the, preceding the library to use) some lines of our php.ini, because we need a library for the connection. In particular the following: extension = php_interbase.dll, extension = php_pdo_odbc.dll and extension = php_pdo_firebird.dll. To function Bookseller need to download fbclient.dll and place in the PHP folder where the others are. We must ensure that we have such libraries in the PHP folder, but to not find them fails.

Now we have to restart Apache to take the libraries.

Once you have installed Laravel 4 in our system, we proceed to download a package called " l4-odbc-driver "and installed following the instructions.

1. Open the composer.json the root of our project and look under "require", in which we see "Laravel / framework": "4.1. *", Because we add just under the following "ccovey / odbc-driver -L4 ":" 1.1.x ".

2. We opened our terminal or command prompt (depending on your operating system) and headed to our project folder and type "install composer".

3. In app / config / app.php look for the line 'Illuminate \ Database \ DatabaseServiceProvider', and will replace by 'Ccovey \ ODBCDriver \ ODBCDriverServiceProvider', to use the driver that you downloaded to connect to the database.

4. The last step is to add the odbc to configuring databases, so we headed to config / database.php and write default odbc "'default' => 'odbc'," and added to the array of connections our odbc connection:

 'Odbc' => array (
            'Driver' => 'odbc'
            'Dsn' => 'DRIVER = Firebird / InterBase (r) driver; UID = SYSDBA; PWD = masterkey; DBNAME = machine: path of the file;'
            'Grammar' => 'DB2'
            'Username' => 'SYSDBA'
            'Password' => 'masterkey'
            'Database' => '',
        ) 

If we want to test the connection, open app / controllers / HomeController.php and within the initial function introduce the following:

 $ Results = DB :: select ('select * from table');
print_r ($ results); 

We headed to the browser to the public folder of your project and if we see data returned from the database is that the connection is successfully established.

Regards

This entry was posted in Laravel , ODBC and tagged , , , , . Bookmark the permalink .



About
Gold User, Rank: 30, Points: 96
Web Developer at Embarcadero Technologies

Comments

Check out more tips and tricks in this development video: