The Illuminate/Database is a comprehensive database toolkit for PHP. It provides an expressive query builder, an ActiveRecord-style ORM, and a schema builder. The illuminate/database package supports various databases, including MySQL, Postgres, SQL Server, and SQLite. The application notably serves as the database layer for the Laravel PHP framework.
You can incorporate Illuminate/Database in your PHP project by creating a new "Capsule" manager instance. This makes the package easy to configure for usage outside the Laravel framework.
To do this, you need to use the code:
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' => '',
]);
Once the Capsule instance has been registered, you can use commands such as:
$users = Capsule::table('users')->where('votes', '>', 100)->get();
$results = Capsule::select('select * from users where id = ?', [1]);
Capsule::schema()->create('users', function ($table) {
$table->increments('id');
$table->string('email')->unique();
$table->timestamps();
});
To use the Eloquent ORM, you can interact with your data models as in:
class User extends Illuminate\Database\Eloquent\Model {}
$users = User::where('votes', '>', 1)->get();
For extended documentation on how to use the various database facilities provided by this library, consult the Laravel framework documentation available on the Laravel website at https://laravel.com/docs.