Skip to content

phattarachai/laravel-odbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ODBC integration for Laravel Framework

This integration allows the use of odbc_* php function with Laravel framework instead of PDO.
It emulates PDO class used by Laravel.

This is a forge from andreossido/laravel-odbc to support latest PHP and Laravel versions.

# How to install

composer require phattarachai/laravel-odbc To add source in your project

# Usage Instructions

It's very simple to configure:

1) Add database to database.php file

'odbc-connection-name' => [
    'driver' => 'odbc',
    'dsn' => 'OdbcConnectionName',
    'database' => 'DatabaseName',
    'host' => '127.0.0.1',
    'username' => 'username',
    'password' => 'password'
]

2) Add service provider in app.php file

'providers' => [
  ...
  Phattarachai\Odbc\ODBCServiceProvider::class
]

# Eloquent ORM

You can use Laravel, Eloquent ORM and other Illuminates components as usual.

# Facade
$books = DB::connection('odbc-connection-name')->table('books')->where('Author', 'Abram Andrea')->get();

# ORM
$books = Book::where('Author', 'Abram Andrea')->get();

# Custom getLastInsertId() function

If you want to provide a custom getLastInsertId() function, you can extends ODBCProcessor class and override function.

class CustomProcessor extends ODBCProcessor
{
    /**
     * @param Builder $query
     * @param null $sequence
     * @return mixed
     */
    public function getLastInsertId(Builder $query, $sequence = null)
    {
        return $query->getConnection()->table($query->from)->latest('id')->first()->getAttribute($sequence);
    }
}

# Custom Processor / QueryGrammar / SchemaGrammar

To use another class instead default one you can update your connection in:

'odbc-connection-name' => [
    'driver' => 'odbc',
    'dsn' => 'OdbcConnectionName',
    'database' => 'DatabaseName',
    'host' => '127.0.0.1',
    'username' => 'username',
    'password' => 'password',
    'options' => [
        'processor' => Illuminate\Database\Query\Processors\Processor::class,   //default
        'grammar' => [
            'query' => Illuminate\Database\Query\Grammars\Grammar::class,       //default
            'schema' => Illuminate\Database\Schema\Grammars\Grammar::class      //default
        ]
    ]
]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages