0

I'm trying to make multiple database connection with laravel.

This is my env file:

DB_CONNECTION=mysql
DB_HOST=ip
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=pass

DB_EXT_HOST=ip
DB_EXT_DATABASE=laravel
DB_EXT_USERNAME=su
DB_EXT_PASSWORD=pass
DB_EXT_PORT=1433

my database.php file

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],
'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host'     => env('DB_EXT_HOST', 'localhost'),
            'port' => env('DB_EXT_PORT', '1433'),
            'database' => env('DB_EXT_DATABASE', 'database'),
            'username' => env('DB_EXT_USERNAME', 'root'),
            'password' => env('DB_EXT_PASSWORD', ''),
            'prefix' => '',
        ],

And I'm trying to connect sqlsrv with this code. But its giving me error.

$db_ext = DB::connection('sqlsrv');

Symfony\Component\Debug\Exception\FatalErrorException] Allowed memory size of 536870912 bytes exhausted (tried to allocate 400560128 bytes)

Bara' ayyash
  • 1,913
  • 1
  • 15
  • 25
Murat Kaya
  • 1,281
  • 3
  • 28
  • 52
  • Are you running a lot of queries, e.g. withing a foreach loop? – Tobias F. May 02 '17 at 12:26
  • @TobiasF. yes but its just giving error only this connection – Murat Kaya May 02 '17 at 12:27
  • Read: http://stackoverflow.com/questions/18775510/laravel-eloquent-memory-leak-retrieving-the-same-record-repeatedly/18776710#18776710 – Troyer May 02 '17 at 12:30
  • @Troyer okay that solved memory size problem but now I'm getting this error. SQLSTATE[01002] Adaptive Server connection failed (severity 9) print_r($db->select('exec sp_EntityFullList')); – Murat Kaya May 02 '17 at 12:49
  • @AbdullaNilam That is something totally different. The error isn't about how to use them, but memory allocation. The title of this post should be changed. – Douwe de Haan May 02 '17 at 14:44

0 Answers0