1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-24 10:53:17 +01:00
php-dibi/examples/connect.php
David Grudl d35a850311 * removed $throwExceptions (always throws)
* added DibiLogger, dibi::notify(), dibi::startLogger()
* miniprofiler dibi::$numOfQueries, $totalTime, $elapsedTime
* simplified DibiException, added DibiDatabaseException
* Dibi::nativeQuery splitted into DibiDriver::doQuery & nativeQuery()
* moved dibi::dumpResult -> DibiResult::dump()
* moved dibi::test() -> DibiDriver::test()
* DibiTranslator generates $mask
2007-09-29 07:53:25 +00:00

112 lines
2.2 KiB
PHP

<h1>dibi connect example</h1>
<?php
require_once '../dibi/dibi.php';
// connects to SQlite
try {
dibi::connect(array(
'driver' => 'sqlite',
'database' => 'sample.sdb',
));
echo '<p>Connected to Sqlite</p>';
} catch (DibiException $e) {
echo '<pre>', $e, '</pre>';
}
// connects to MySQL using DSN
try {
dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=utf8');
echo '<p>Connected to MySQL</p>';
} catch (DibiException $e) {
echo '<pre>', $e, '</pre>';
}
// connects to MySQL / MySQLi
try {
dibi::connect(array(
'driver' => 'mysql', // or 'mysqli'
'host' => 'localhost',
'username' => 'root',
'password' => 'xxx',
'database' => 'dibi',
'charset' => 'utf8',
));
echo '<p>Connected to MySQL</p>';
} catch (DibiException $e) {
echo '<pre>', $e, '</pre>';
}
// connects to ODBC
try {
dibi::connect(array(
'driver' => 'odbc',
'username' => 'root',
'password' => '***',
'database' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq='.dirname(__FILE__).'/sample.mdb',
));
echo '<p>Connected to ODBC</p>';
} catch (DibiException $e) {
echo '<pre>', $e, '</pre>';
}
// connects to PostgreSql
try {
dibi::connect(array(
'driver' => 'postgre',
'string' => 'host=localhost port=5432 dbname=mary',
'persistent' => TRUE,
));
echo '<p>Connected to PostgreSql</p>';
} catch (DibiException $e) {
echo '<pre>', $e, '</pre>';
}
// connects to PDO
try {
dibi::connect(array(
'driver' => 'pdo',
'dsn' => 'sqlite2::memory:',
));
echo '<p>Connected to Sqlite via PDO</p>';
} catch (DibiException $e) {
echo '<pre>', $e, '</pre>';
}
// connects to MS SQL
try {
dibi::connect(array(
'driver' => 'mssql',
'host' => 'localhost',
'username' => 'root',
'password' => 'xxx',
));
echo '<p>Connected to MS SQL</p>';
} catch (DibiException $e) {
echo '<pre>', $e, '</pre>';
}