使用 Eloquent 模块
Eloquent 模块引入
composer require illuminate/database
如果使用分页的话,还要引入 illuminate/database
composer require illuminate/database
程序头部公共部分,引入composer加载器。例:
include __DIR__ . '/vendor/autoload.php';
配置并初始化 Eloquent :
新建文件 eloquent.php
。
引入composer加载器之后,再引入 eloquent.php
初始化文件
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
使用 Eloquent 模型:
use Illuminate\Database\Eloquent\Model as Eloquent;
class User extends Eloquent
{
protected $table = 'users';
}
整合laravel的ORM,Eloquent模块 https://blog.csdn.net/leigin/article/details/95312246
官方组件:https://github.com/illuminate/database