Revision: Fri, 24 Nov 2023 16:17:08 GMT
v3.0 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.10
Edit this page

Database - Query Builders

You can read how to work with Database using manually written queries here.

The DBAL component includes a set of query builders used to unify the way of working with different databases and simplify migration to different DBMS over the lifetime of the application.

Before we start

To demonstrate query building abilities, let's first declare a sample table in our default database:

namespace App\Controller;

use Cycle\Database\Database;

class HomeController
    public function index(Database $db): void
        $schema = $db->table('test')->getSchema();

        $schema->enum('status', ['active', 'disabled'])->defaultValue('active');
        $schema->string('name', 64);

You can read more about declaring database schemas here.

You can find Full documentation about using Query builder here.