mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 13:17:58 +02:00
added NClass
This commit is contained in:
@@ -71,7 +71,7 @@ interface DibiVariableInterface
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class dibi
|
||||
class dibi extends NClass
|
||||
{
|
||||
/**
|
||||
* Column type in relation to PHP native type
|
||||
@@ -157,13 +157,6 @@ class dibi
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Monostate class
|
||||
*/
|
||||
final private function __construct()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new DibiDriver object and connects it to specified database
|
||||
*
|
||||
|
@@ -453,28 +453,24 @@ abstract class DibiResult extends NObject implements IteratorAggregate, Countabl
|
||||
*/
|
||||
public function dump()
|
||||
{
|
||||
echo '<table class="dump">';
|
||||
echo '<thead>';
|
||||
echo '<tr>';
|
||||
echo '<th>#row</th>';
|
||||
echo "\n<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n";
|
||||
|
||||
foreach ($this->getFields() as $field) {
|
||||
echo '<th>' . htmlSpecialChars($field) . '</th>';
|
||||
echo "\t\t<th>" . htmlSpecialChars($field) . "</th>\n";
|
||||
}
|
||||
echo '</tr>';
|
||||
echo '</thead>';
|
||||
echo '<tbody>';
|
||||
|
||||
echo "\t</tr>\n</thead>\n<tbody>\n";
|
||||
|
||||
foreach ($this as $row => $fields) {
|
||||
echo '<tr><th>', $row, '</th>';
|
||||
echo "\t<tr>\n\t\t<th>", $row, "</th>\n";
|
||||
foreach ($fields as $field) {
|
||||
//if (is_object($field)) $field = $field->__toString();
|
||||
echo '<td>', htmlSpecialChars($field), '</td>';
|
||||
echo "\t\t<td>", htmlSpecialChars($field), "</td>\n";
|
||||
}
|
||||
echo '</tr>';
|
||||
echo "\t</tr>\n";
|
||||
}
|
||||
|
||||
echo '</tbody>';
|
||||
echo '</table>';
|
||||
echo "</tbody>\n</table>\n";
|
||||
}
|
||||
|
||||
|
||||
|
@@ -76,23 +76,11 @@ abstract class NObject
|
||||
/**
|
||||
* Access to reflection
|
||||
*
|
||||
* @return ReflectionClass
|
||||
* @return ReflectionObject
|
||||
*/
|
||||
final public function getReflection()
|
||||
{
|
||||
return new ReflectionClass(get_class($this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return hash id for given object
|
||||
*
|
||||
* @return string 32 hexa chars
|
||||
*/
|
||||
final public function getHashId()
|
||||
{
|
||||
return spl_object_hash($this);
|
||||
return new ReflectionObject($this);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +205,7 @@ abstract class NObject
|
||||
|
||||
|
||||
/**
|
||||
* Is method defined? Case sensitive, filters protected & private, doesn't recognize static methods (works good since 5.0.4)
|
||||
* Does method exist? Case sensitive, filters protected & private, doesn't recognize static methods (works good since 5.0.4)
|
||||
*
|
||||
* @param string class name
|
||||
* @param string method name
|
||||
@@ -236,4 +224,18 @@ abstract class NObject
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* NClass is the ultimate ancestor of all uninstantiable classes.
|
||||
*/
|
||||
abstract class NClass
|
||||
{
|
||||
|
||||
final public function __construct()
|
||||
{
|
||||
throw new LogicException("Cannot instantiate static class " . get_class($this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,36 +1,42 @@
|
||||
<h1>dibi connect example</h1>
|
||||
<h1>dibi::connect() example</h1>
|
||||
<?php
|
||||
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
|
||||
// connects to SQlite
|
||||
echo '<p>Connecting to Sqlite: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite',
|
||||
'database' => 'sample.sdb',
|
||||
));
|
||||
echo '<p>Connected to Sqlite</p>';
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
|
||||
|
||||
// connects to MySQL using DSN
|
||||
echo '<p>Connecting to MySQL: ';
|
||||
try {
|
||||
dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=utf8');
|
||||
echo '<p>Connected to MySQL</p>';
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
|
||||
|
||||
// connects to MySQLi using array
|
||||
echo '<p>Connecting to MySQL: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'mysqli',
|
||||
@@ -40,16 +46,18 @@ try {
|
||||
'database' => 'dibi',
|
||||
'charset' => 'utf8',
|
||||
));
|
||||
echo '<p>Connected to MySQL</p>';
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
|
||||
|
||||
// connects to ODBC
|
||||
echo '<p>Connecting to ODBC: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'odbc',
|
||||
@@ -57,46 +65,52 @@ try {
|
||||
'password' => '***',
|
||||
'database' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq='.dirname(__FILE__).'/sample.mdb',
|
||||
));
|
||||
echo '<p>Connected to ODBC</p>';
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
|
||||
|
||||
// connects to PostgreSql
|
||||
echo '<p>Connecting to PostgreSql: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'postgre',
|
||||
'string' => 'host=localhost port=5432 dbname=mary',
|
||||
'persistent' => TRUE,
|
||||
));
|
||||
echo '<p>Connected to PostgreSql</p>';
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
|
||||
|
||||
// connects to PDO
|
||||
echo '<p>Connecting to Sqlite via PDO: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'pdo',
|
||||
'dsn' => 'sqlite2::memory:',
|
||||
));
|
||||
echo '<p>Connected to Sqlite via PDO</p>';
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
|
||||
// connects to MS SQL
|
||||
echo '<p>Connecting to MS SQL: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'mssql',
|
||||
@@ -104,15 +118,17 @@ try {
|
||||
'username' => 'root',
|
||||
'password' => 'xxx',
|
||||
));
|
||||
echo '<p>Connected to MS SQL</p>';
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
|
||||
// connects to Oracle
|
||||
echo '<p>Connecting to Oracle: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'oracle',
|
||||
@@ -120,8 +136,9 @@ try {
|
||||
'password' => 'xxx',
|
||||
'database' => 'db',
|
||||
));
|
||||
echo '<p>Connected to Oracle</p>';
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
}
|
||||
echo "</p>\n";
|
@@ -1,4 +1,4 @@
|
||||
<h1>dibi user datatype example</h1>
|
||||
<h1>DibiVariableInterface example</h1>
|
||||
<?php
|
||||
|
||||
require_once '../dibi/dibi.php';
|
||||
|
@@ -23,9 +23,7 @@ try {
|
||||
$res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < %i', 38);
|
||||
|
||||
} catch (DibiException $e) {
|
||||
|
||||
echo '<h2>Dibi Exception:</h2>';
|
||||
echo '<pre>', $e, '</pre>';
|
||||
echo '<p>', get_class($e), ': ', $e->getMessage(), '</p>';
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user