2017-07-21 21:34:37 +02:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
?>
|
2010-08-03 12:28:07 +02:00
|
|
|
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">
|
|
|
|
|
2018-05-10 21:45:11 +02:00
|
|
|
<h1>Connecting to Databases | Dibi</h1>
|
2010-08-03 12:28:07 +02:00
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
<?php
|
|
|
|
|
2018-03-23 11:57:59 +01:00
|
|
|
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
|
|
|
die('Install packages using `composer install`');
|
|
|
|
}
|
2008-07-17 03:51:29 +00:00
|
|
|
|
|
|
|
|
2018-05-10 21:45:11 +02:00
|
|
|
// connects to SQlite using Dibi class
|
2008-07-17 03:51:29 +00:00
|
|
|
echo '<p>Connecting to Sqlite: ';
|
|
|
|
try {
|
2015-10-06 01:39:01 +02:00
|
|
|
dibi::connect([
|
2018-05-23 17:08:25 +02:00
|
|
|
'driver' => 'sqlite',
|
2014-05-13 15:56:44 +02:00
|
|
|
'database' => 'data/sample.s3db',
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2008-07-17 03:51:29 +00:00
|
|
|
echo 'OK';
|
2015-10-08 02:13:22 +02:00
|
|
|
} catch (Dibi\Exception $e) {
|
2008-07-17 03:51:29 +00:00
|
|
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
echo "</p>\n";
|
|
|
|
|
|
|
|
|
2015-10-08 02:13:22 +02:00
|
|
|
// connects to SQlite using Dibi\Connection object
|
2010-08-03 11:48:51 +02:00
|
|
|
echo '<p>Connecting to Sqlite: ';
|
|
|
|
try {
|
2015-10-08 02:13:22 +02:00
|
|
|
$connection = new Dibi\Connection([
|
2018-05-23 17:08:25 +02:00
|
|
|
'driver' => 'sqlite',
|
2014-05-13 15:56:44 +02:00
|
|
|
'database' => 'data/sample.s3db',
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2010-08-03 11:48:51 +02:00
|
|
|
echo 'OK';
|
2015-10-08 02:13:22 +02:00
|
|
|
} catch (Dibi\Exception $e) {
|
2010-08-03 11:48:51 +02:00
|
|
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
echo "</p>\n";
|
|
|
|
|
|
|
|
|
2018-04-17 15:01:30 +02:00
|
|
|
// connects to MySQLi
|
2010-08-03 11:48:51 +02:00
|
|
|
echo '<p>Connecting to MySQLi: ';
|
2008-07-17 03:51:29 +00:00
|
|
|
try {
|
2015-10-06 01:39:01 +02:00
|
|
|
dibi::connect([
|
2015-06-19 03:11:36 +02:00
|
|
|
'driver' => 'mysqli',
|
|
|
|
'host' => 'localhost',
|
2008-07-17 03:51:29 +00:00
|
|
|
'username' => 'root',
|
|
|
|
'password' => 'xxx',
|
|
|
|
'database' => 'dibi',
|
2015-10-06 01:39:01 +02:00
|
|
|
'options' => [
|
2015-06-19 03:11:36 +02:00
|
|
|
MYSQLI_OPT_CONNECT_TIMEOUT => 30,
|
2015-10-06 01:39:01 +02:00
|
|
|
],
|
2015-06-19 03:11:36 +02:00
|
|
|
'flags' => MYSQLI_CLIENT_COMPRESS,
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2008-07-17 03:51:29 +00:00
|
|
|
echo 'OK';
|
2015-10-08 02:13:22 +02:00
|
|
|
} catch (Dibi\Exception $e) {
|
2008-07-17 03:51:29 +00:00
|
|
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
echo "</p>\n";
|
|
|
|
|
|
|
|
|
|
|
|
// connects to ODBC
|
|
|
|
echo '<p>Connecting to ODBC: ';
|
|
|
|
try {
|
2015-10-06 01:39:01 +02:00
|
|
|
dibi::connect([
|
2015-06-19 03:11:36 +02:00
|
|
|
'driver' => 'odbc',
|
2008-07-17 03:51:29 +00:00
|
|
|
'username' => 'root',
|
|
|
|
'password' => '***',
|
2018-04-17 10:03:43 +02:00
|
|
|
'dsn' => 'Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=' . __DIR__ . '/data/sample.mdb',
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2008-07-17 03:51:29 +00:00
|
|
|
echo 'OK';
|
2015-10-08 02:13:22 +02:00
|
|
|
} catch (Dibi\Exception $e) {
|
2008-07-17 03:51:29 +00:00
|
|
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
echo "</p>\n";
|
|
|
|
|
|
|
|
|
|
|
|
// connects to PostgreSql
|
|
|
|
echo '<p>Connecting to PostgreSql: ';
|
|
|
|
try {
|
2015-10-06 01:39:01 +02:00
|
|
|
dibi::connect([
|
2015-06-19 03:11:36 +02:00
|
|
|
'driver' => 'postgre',
|
|
|
|
'string' => 'host=localhost port=5432 dbname=mary',
|
2017-07-11 12:28:13 +02:00
|
|
|
'persistent' => true,
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2008-07-17 03:51:29 +00:00
|
|
|
echo 'OK';
|
2015-10-08 02:13:22 +02:00
|
|
|
} catch (Dibi\Exception $e) {
|
2008-07-17 03:51:29 +00:00
|
|
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
echo "</p>\n";
|
|
|
|
|
|
|
|
|
|
|
|
// connects to PDO
|
|
|
|
echo '<p>Connecting to Sqlite via PDO: ';
|
|
|
|
try {
|
2015-10-06 01:39:01 +02:00
|
|
|
dibi::connect([
|
2015-06-19 03:11:36 +02:00
|
|
|
'driver' => 'pdo',
|
2014-06-02 16:50:01 +02:00
|
|
|
'dsn' => 'sqlite::memory:',
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2008-07-17 03:51:29 +00:00
|
|
|
echo 'OK';
|
2015-10-08 02:13:22 +02:00
|
|
|
} catch (Dibi\Exception $e) {
|
2008-07-17 03:51:29 +00:00
|
|
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
echo "</p>\n";
|
|
|
|
|
|
|
|
|
2015-10-22 01:53:41 +02:00
|
|
|
// connects to SQLSRV
|
2015-11-06 23:00:36 +01:00
|
|
|
echo '<p>Connecting to Microsoft SQL Server: ';
|
2010-05-19 15:36:56 +02:00
|
|
|
try {
|
2015-10-06 01:39:01 +02:00
|
|
|
dibi::connect([
|
2015-10-22 01:53:41 +02:00
|
|
|
'driver' => 'sqlsrv',
|
2015-06-19 03:11:36 +02:00
|
|
|
'host' => '(local)',
|
2010-05-19 15:36:56 +02:00
|
|
|
'username' => 'Administrator',
|
|
|
|
'password' => 'xxx',
|
|
|
|
'database' => 'main',
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2010-05-19 15:36:56 +02:00
|
|
|
echo 'OK';
|
2015-10-08 02:13:22 +02:00
|
|
|
} catch (Dibi\Exception $e) {
|
2010-05-19 15:36:56 +02:00
|
|
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
echo "</p>\n";
|
|
|
|
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
// connects to Oracle
|
|
|
|
echo '<p>Connecting to Oracle: ';
|
|
|
|
try {
|
2015-10-06 01:39:01 +02:00
|
|
|
dibi::connect([
|
2015-06-19 03:11:36 +02:00
|
|
|
'driver' => 'oracle',
|
2008-07-17 03:51:29 +00:00
|
|
|
'username' => 'root',
|
|
|
|
'password' => 'xxx',
|
|
|
|
'database' => 'db',
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2008-07-17 03:51:29 +00:00
|
|
|
echo 'OK';
|
2015-10-08 02:13:22 +02:00
|
|
|
} catch (Dibi\Exception $e) {
|
2008-07-17 03:51:29 +00:00
|
|
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
|
|
|
}
|
2011-07-01 08:06:36 +02:00
|
|
|
echo "</p>\n";
|