Laravel-Framework/src/Illuminate/Database
Taylor Otwell d4edbf5f25
Apply fixes from StyleCI (#29062)
2019-07-03 11:39:03 -06:00
..
Capsule Avoid call_user_func_array in __call functions (#14791) 2016-08-12 13:26:25 -05:00
Concerns formatting 2018-08-20 09:23:56 -05:00
Connectors Apply fixes from StyleCI (#29062) 2019-07-03 11:39:03 -06:00
Console add tests. extract class 2018-07-14 10:24:12 -05:00
Eloquent Apply fixes from StyleCI (#29062) 2019-07-03 11:39:03 -06:00
Events Fix database events phpdoc (#22420) 2017-12-13 21:21:34 -06:00
Migrations formatting 2018-06-22 10:18:54 -05:00
Query Apply fixes from StyleCI (#29062) 2019-07-03 11:39:03 -06:00
Schema Apply fixes from StyleCI (#29062) 2019-07-03 11:39:03 -06:00
Connection.php fix spelling 2018-07-21 21:39:55 -05:00
ConnectionInterface.php Revert "Fix ConnectionInterface methods (#25092)" 2018-08-05 11:34:04 +01:00
ConnectionResolver.php Additional cs fixes 2015-06-01 16:39:11 +01:00
ConnectionResolverInterface.php Fix typehint 2015-07-15 22:52:14 +02:00
DatabaseManager.php Apply fixes from StyleCI (#29062) 2019-07-03 11:39:03 -06:00
DatabaseServiceProvider.php Make consistent the disuse of helper functions within ServiceProviders (#18521) 2017-03-28 08:05:02 -05:00
DetectsDeadlocks.php Detect MySQL Galera deadblocks. (#22214) 2017-11-26 09:35:13 -06:00
DetectsLostConnections.php Handle AWS Connection Lost (#25295) 2018-08-22 07:36:34 -05:00
Grammar.php optimize method calls (#24783) 2018-07-09 16:39:34 -04:00
MigrationServiceProvider.php Move all framework command registration into ArtisanServiceProvider. 2016-12-19 14:12:17 -06:00
MySqlConnection.php refactor to use Builder 2017-03-26 13:01:46 +00:00
PostgresConnection.php refactor to use Builder 2017-03-26 13:01:46 +00:00
QueryException.php No need to set twice. (#17215) 2017-01-09 08:16:13 -06:00
README.md fix psr-2: database readme sample code (#19490) 2017-06-06 06:25:35 -05:00
SQLiteConnection.php refactor to use Builder 2017-03-26 13:01:46 +00:00
Seeder.php make call chainable (#22288) 2017-12-03 08:43:12 -06:00
SqlServerConnection.php refactor to use Builder 2017-03-26 13:01:46 +00:00
composer.json Fix version of doctrine/dbal for PHP 7.1 (#22563) 2017-12-28 21:09:12 -06:00

README.md

Illuminate Database

The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style ORM, and schema builder. It currently supports MySQL, Postgres, SQL Server, and SQLite. It also serves as the database layer of the Laravel PHP framework.

Usage Instructions

First, create a new "Capsule" manager instance. Capsule aims to make configuring the library for usage outside of the Laravel framework as easy as possible.

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'    => '',
]);

// Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));

// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();

composer require "illuminate/events" required when you need to use observers with Eloquent.

Once the Capsule instance has been registered. You may use it like so:

Using The Query Builder

$users = Capsule::table('users')->where('votes', '>', 100)->get();

Other core methods may be accessed directly from the Capsule in the same manner as from the DB facade:

$results = Capsule::select('select * from users where id = ?', array(1));

Using The Schema Builder

Capsule::schema()->create('users', function ($table) {
    $table->increments('id');
    $table->string('email')->unique();
    $table->timestamps();
});

Using The Eloquent ORM

class User extends Illuminate\Database\Eloquent\Model {}

$users = User::where('votes', '>', 1)->get();

For further documentation on using the various database facilities this library provides, consult the Laravel framework documentation.