ar\connect\db

This module provides an API to access to many different database systems. It is based on PDO.

Example:

<pinp>
$db = ar('connect/db')-> connect('mysql:dbname=test;host=localhost','user','password');
if ( ar('error')->isError( $db ) ) {
echo 'Error: '.$db->getMessage().' - '.$db->getCode();
} else {
$result = $db->prepare( 'select field from table' );
foreach ( $result as $row ) {
echo $row['field'];
}
}
</pinp>

methods

(object) client Creates a new database client object and returns it.
(object) connect Deprecated. Use client() instead.

client

Available in Ariadne > 2.7.3

(object) ar('connect/db')->client( $dsn, $user = '', $password = '', $options = array() )

(string) $dsn The Data Source Name, contains information required to connect to the database.
(string) $user The user name for the DSN string.
(string) $password The password for the DSN string.
(array) $options A key => value array of driver specific connection options.

This method creates a new PDO connection to a database and returns it. See the PHP documentation for more information.

connect

Deprecated in Ariadne > 2.7.3

(object) ar('connect/db')->connect( $dsn, $user = '', $password = '', $options = array() )

(string) $dsn The Data Source Name, contains information required to connect to the database.
(string) $user The user name for the DSN string.
(string) $password The password for the DSN string.
(array) $options A key => value array of driver specific connection options.

This method creates a new PDO connection to a database and returns it. See the PHP documentation for more information.