__construct

DALMP\Database takes the parameters from a DNS (database source name) so before you can start using it you need to define this values.

DSN format

charset://username:password@host:port/database

When using Unix domain sockets:

charset://username:password@unix_socket=\path\of\the.socket/database
  • Notice that the path of the socket is using backslashes.
\path\of\the.socket

Will be translated to:

/path/of/the.socket

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';

require_once 'dalmp.php';

$DSN = "utf8://$user:$password@127.0.0.1/test";

$db = new DALMP\Database($DSN);

try {
    $rs = $db->getOne('SELECT now()');
} catch (\Exception $e) {
    print_r($e->getMessage());
}

/**
 * 1 log to single file
 * 2 log to multiple files (creates a log per request)
 * 'off' to stop debuging
 */
$db->debug(1);

echo $db, PHP_EOL; // print connection details

If you wan to use the system default charset the DSN would be:

1
$DSN = "mysql://$user:$password@127.0.0.1/test";
  • notice the mysql:// instead of the utf8://

See also

Quickstart.

Thanks Navicat for supporting Open Source projects.

Navicat



A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.

Donating helps ensure continued support, development and availability.

dalmp


comments powered by Disqus