Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Latest commit

 

History

History
98 lines (58 loc) · 3.3 KB

connection.rst

File metadata and controls

98 lines (58 loc) · 3.3 KB

Connection

DSQL supports various database vendors natively but also supports 3rd party extensions. For current status on database support see: databases.

Connection class is handy to have if you plan on building and executing queries in your application. It's more appropriate to store connection in a global variable or global class:

$app->db = Atk4\Dsql\Connection::connect($dsn, $user, $pass, $args);

This should allow you to access this class from anywhere and generate either new Query or Expression class:

$query = $app->db->dsql();

// or

$expr = $app->db->expr('show tables');

Here is how you can use all of this together:

$dsn = 'mysql:host=localhost;port=3307;dbname=testdb';

$connection = Atk4\Dsql\Connection::connect($dsn, 'root', 'root');

echo "Time now is : ". $connection->expr("select now()");

:phpconnect will determine appropriate class that can be used for this DSN string. This can be a PDO class or it may try to use a 3rd party connection class.

Connection class is also responsible for executing queries. This is only used if you connect to vendor that does not use PDO.

Developers can register custom classes to handle driver types using the Connecion::registerConnectionClass method:

Connection::registerConnectionClass(Custom\MySQL\Connection::class, 'mysql'); // or directly using the class
Custom\MySQL\Connection::registerConnectionClass();