Last active
March 25, 2018 03:41
-
-
Save ronokdev/05eb291a49c8044354f588daa6ba0e20 to your computer and use it in GitHub Desktop.
Connect & Raw Query From a Second Database (Laravel 5.6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Open → config/database.php & Search for 'mysql' | |
2. Add new Mysql Connection like below (Laravel 5.6) → | |
'mysql_2' => [ | |
'driver' => 'mysql', | |
'host' => env('DB_HOST', '127.0.0.1'), | |
'port' => env('DB_PORT', '3306'), | |
'database' => 'dbName', | |
'username' => 'Username', | |
'password' => 'Pass', | |
'unix_socket' => env('DB_SOCKET', ''), | |
// 'charset' => 'utf8mb4', | |
// 'collation' => 'utf8mb4_unicode_ci', | |
'charset' => 'utf8', | |
'collation' => 'utf8_unicode_ci', | |
'prefix' => '', | |
'strict' => false, //Important | |
'engine' => null, | |
], | |
3. In Controller add this & you are good to Go → | |
$results = DB::connection('mysql_2')->select("Your RAW QUERY"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment