Skip to content

Instantly share code, notes, and snippets.

@homleen
Created May 15, 2013 11:20
Show Gist options
  • Save homleen/5583294 to your computer and use it in GitHub Desktop.
Save homleen/5583294 to your computer and use it in GitHub Desktop.
Create a custom database (mysql) connection in Laravel 3.x. Not in config file.
<?php
/**
* Author: Lynn
* Email: homlean(at)gmail.com
*/
Route::get(
'test', function () {
$config = array(
'driver' => 'mysql',
'host'=>'127.0.0.1',
'database' => 'nymph',
'username' => 'iweb',
'password' => 'iweb',
'charset' => 'utf8',
'prefix' => ''
);
$connector = new \Laravel\Database\Connectors\MySQL;
$connection = new \Laravel\Database\Connection($connector->connect($config), $config);
dd($connection->query('select * from users'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment