\Omega\Database\Adapter AbstractDatabaseAdapter

Abstract database adapter class.

The AbstractDatabaseAdapter is designed to provide a basic abstraction for database connection and management. This class is declared as abstract and offers a basic implementation of several methods defined in the DatabaseAdapterInterface interface.

Summary

Methods
Properties
Constants
__construct
pdo
checkIfDatabaseExists
hasTable
query
createTable
alterTable
getTables
dropTables
pdo
No public constants found
No protected methods found
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Properties

$pdo

$pdo : \Pdo

Pdo instance.

Type

Pdo — Holds an instance of Pdo.

Methods

__construct()

__construct(string  $dsn, string  $username = '', string  $password = '') : mixed

Constructs a new database adapter instance.

Parameters

string $dsn

The Data Source Name (DSN) for the database connection.

string $username

The username for the database connection.

string $password

The password for the database connection.

Throws

\Omega\Database\Exception\AdapterException

if the PDO extension is not installed or enabled.

\Omega\Database\Exception\ConnectionException

if the database connection fails.

\PDOException

Returns

mixed —

pdo()

pdo() : \Pdo

Get the underlying PDO instance for this connection.

Throws

\Omega\Database\Exception\AdapterException

if pdo extension is not installed or not enabled.

Returns

\Pdo —

Returns the current PDO instance that represents the database connection.

checkIfDatabaseExists()

checkIfDatabaseExists(string  $host, string  $port, string  $username, string  $password) : void

Check if database exists, otherwise create it.

Parameters

string $host

Holds the host of the database.

string $port

Holds the port number.

string $username

Holds the username for the connection.

string $password

Holds the password for the connection.

Returns

void —

hasTable()

hasTable(string  $name) : bool

Check if a table exists on this connection.

Parameters

string $name

The name of the table to check.

Returns

bool —

Returns true if the specified table exists, otherwise returns false.

query()

query() : \Omega\Database\QueryBuilder\AbstractQueryBuilder

Start a new query builder on this connection.

Returns

\Omega\Database\QueryBuilder\AbstractQueryBuilder —

An instance of the AbstractQueryBuilder class for constructing SQL queries.

createTable()

createTable(string  $table) : \Omega\Database\Migration\AbstractMigration

Start a new migration to create a table on this connection.

Parameters

string $table

The name of the table to create.

Returns

\Omega\Database\Migration\AbstractMigration —

Returns an instance of the AbstractMigration class for managing table creation.

alterTable()

alterTable(string  $table) : \Omega\Database\Migration\AbstractMigration

Start a new migration to modify an existing table on this connection.

Parameters

string $table

The name of the table to modify.

Returns

\Omega\Database\Migration\AbstractMigration —

Returns an instance of the AbstractMigration class for managing table alterations.

getTables()

getTables() : string[]

Get the list of table names on this connection.

Returns

string[] —

Returns an array of table names available on this connection.

dropTables()

dropTables() : int|bool

Drop all tables in the current database. Use with caution.

Returns

int|bool —

Returns 1 if all tables are successfully dropped, or false if any issues occur during the process.