Getting Started - TerminusStudio/ezDB GitHub Wiki

This page contains all the information you need to get started with ezDB.

ezDB can be installed with or without composer. You can view the installation instructions here: https://github.com/TerminusStudio/ezDB/wiki#install

Once installed you can straight away use it to create a connection by instantiating a new Connection object.

$config = [
        'driver' => 'mysql',
        'host' => 'localhost',
        'database' => 'database',
        'username' => 'user',
        'password' => 'pass'
 ];

//Create a DatabaseConfig Instance
$dbConfig = new \TS\ezDB\DatabaseConfig($config);

//Create a Connection.
$connection = new \TS\ezDB\Connection($dbConfig);

//Connection is not yet opened with the database yet and it will be automatically opened if you call execute any queries. You can also manually open it by calling the connect() method.
$connection->connect();

You can read more about the Connection class and all of its methods here: https://github.com/TerminusStudio/ezDB/wiki/1.-Connection#connection

Using the Connections class

The better way to manage connection is by using the connections class.

Connections::add($dbConfig);

Connections::connection()->connect();

There is also a connections manager which allows you to manage multiple connections and call it anywhere you want from within your code. You can read more about the Connections class here: https://github.com/TerminusStudio/ezDB/wiki/1.-Connection#connections

Builder

Once you have your connection, you can straight away use it in a Builder.

 $builder = new Builder($connection)
                ->table('test_table')
                ->get();

Or if you want cleaner looking code, (Read more about DB Class here).

 $builder = DB::table('test_table')->get(); 

//if you did not use the Connections class, then pass in the $connection instance as the second parameter to the table method.
 $builder = DB::table('test_table', $connection)->get(); 

Models

Making use of Model classes is similar to Eloquent and you can read about that here: https://github.com/TerminusStudio/ezDB/wiki/3.-Model