DB - TerminusStudio/ezDB GitHub Wiki

The DB class provides easy access to certain methods to make your code look cleaner.

All of the functions in the DB class accept a last optional parameter for the connection. It can either be the name of the connection if you are utilizing the Connections class, or a Connection. If the connection is not set, it will use the default connection set in Connections class.

Table

The table function returns a new builder instance which you can directly use to build the query. The function accepts two parameters, the table name and an optional connection.

public static function table($table, $connection = null): Builder;

Statement

This functions allows you to quickly execute a statement on the database. It accepts two parameters, the SQL statement and an optional connection.

public static function statement($sql, $connection = null): array|bool|int|mixed|object;

Depending on your query and driver the return type might vary. Take a look at the Driver->query() method for more information.

Select

This function allows you to easily run a prepared select statement on the database. It accepts three parameters, the SQL statement, an optional array containing values that needs to be binded and the optional connection.

public static function select($sql, $params = [], $connection = null): array|bool|int|mixed|object;

The return type will vary depending on the output from the driver.

Raw

This function returns an instance of Raw class that can be used to execute queries on the database or to extend functionality of the Builder. It accepts two parameters, the SQL statement and an optional connection.

The connection parameter is only needed if the Raw class is used for executing queries directly.

public static function raw($sql, $connection = null);

This can be used when using whereRaw for example,

DB::table('user')->whereRaw(DB::raw("id = 10"))->get();