Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (62 sloc) 1.86 KB

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();

Resources

You can’t perform that action at this time.