Giter Club home page Giter Club logo

odbc's Introduction

Laravel ODBC Connector

This is a simple ODBC connector for Laravel 4/5.

Installation

Add this to the require section in your composer.json file

"tck/odbc": "dev-master"

In your config/app.php file add the Service Provider to the service providers array like so...

'TCK\Odbc\OdbcServiceProvider',

Now in your config/database.php you will need to add your connection details, it'll look something like this...

'odbc'   => [
	'driver'   => 'odbc',
	'dsn'      => 'odbc:DB_CONNECTION_STRING', //
	'host'     => 'DB_HOST',
	'database' => 'DB_NAME,
	'username' => 'DB_USERNAME',
	'password' => 'DB_PASSWORD',
],

Custom Grammar

To use SQL Server or other database engines, set the grammar in the config:

'odbc'   => [
	...
	'grammar' => [
		'query' => Illuminate\Database\Query\Grammars\SqlServerGrammar::class,
		'schema' => Illuminate\Database\Schema\Grammars\SqlServerGrammar::class,
	],
],

Usage

Now in your app you can do something like...

$data = DB::connection('odbc')->get('tableName')->all();

Alternatively, in an Eloquent model you could something like this

class Users extends Eloquent {

	protected $connection = 'odbc';
}

DB_CONNECTION_STRING - Something to note

Dependant upon your database configuration, I personally had some difficulty in working out what the DB_CONNECTION_STRING needed to be.

This was some trial and error (with a hell of a lot of Googling!) but you could either use a path, something like...

'dsn'      => 'odbc:\\\\path\to\my\database',

Or a connection name

'dsn'      => 'odbc:\\\\my-connection-name',

Hopefully, this will help you!

odbc's People

Contributors

bencarter78 avatar mlntn avatar totalpeopleltd avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.