Laravelde iki database kullanma
app/config/database.php
Use the second DB in Eloquent Model
Use the second DB Connection in Controller
Query Builder
Elequentde de şu şekilde kullanıyoruz
<?php
class Sinav extends Eloquent {
protected $connection = 'mysql2';
protected $table = 'sinav';
}
<?php
return array(
'default' => 'mysql',
'connections' => array(
# Our primary database connection
'mysql' => array(
'driver' => 'mysql',
'host' => 'host1',
'database' => 'database1',
'username' => 'user1',
'password' => 'pass1'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
# Our secondary database connection
'mysql_2' => array(
'driver' => 'mysql',
'host' => 'host2',
'database' => 'database2',
'username' => 'user2',
'password' => 'pass2'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
);
<?php
class Sinav extends Eloquent {
protected $connection = 'mysql2';
protected $table = 'sinav';
}
Comments
Post a Comment