PHP Eloquentライブラリの勉強を始めました。
今回はmydbというデータベースのjobsテーブルに接続する方法です。
DB接続
require_once './vendor/autoload.php';
$db = new Illuminate\Database\Capsule\Manager;
$db->addConnection
([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'mydb',
'username' => 'root',
'pasword' => ''
]);
$db->setAsGlobal();
$db->bootEloquent();
class Jobs extends Illuminate\Database\Eloquent\Model {
}
$results = Jobs::all();
SQL文なしに全レコードを表示できます。