webiik / database
The Database is PDO connection container.
1.1
2020-07-08 12:56 UTC
Requires
- php: >=7.2
This package is auto-updated.
Last update: 2024-11-08 22:13:55 UTC
README
Database
The Database is PDO connection container.
Installation
composer require webiik/database
Example
$db = new \Webiik\Database\Database(); $db->add('main', 'mysql', 'localhost', 'webiik', 'root', 'root'); $pdo = $db->connect();
Settings
add
add(string $name, string $driver, string $host, string $databaseName, string $user, string $password, array $options = [], array $commands = []): void
add() adds database connection credentials.
Parameters
- name name of current database connection. You will be able to get this connection by this name.
- driver pdo driver
- host host name e.g. localhost
- databaseName database name
- user database user name
- password database user password
- options array of PDO options
- commands associative array of MySQL commands with parameters to execute after connecting to database. E.g. ['SET CHARACTER SET ?' => 'utf8']
$db->add('main', 'mysql', 'localhost', 'webiik', 'root', 'root');
Connection
connect
connect(string $name = ''): \PDO
connect() connects to database and return PDO object. When name is omitted it connects to first added database.
$pdo = $db->connect();
disconnect
disconnect(string $name = ''): void
disconnect() disconnects from database. When name is omitted it disconnects from first added database.
$db->disconnect();