<?php
/* Nesneye Dayalı Programlama (OOP) */
final class Config{
static $confArray;
public static function read($name){
return self::$confArray[$name];
}
public static function write($name, $value){
self::$confArray[$name] = $value;
}
}
class DamraKOC{
public static $instance;
public function __construct(){
// Sistem tarafından kullanılabilir veritabanları
echo "<pre>";
print_r(PDO::getAvailableDrivers());
echo "</pre>";
str_repeat("
",10);
$dsn = Config::read('db.type').
':host=' . Config::read('db.host') .
';dbname=' . Config::read('db.dbname') .
';port=' . Config::read('db.port') .
';connect_timeout=15';
$user = Config::read('db.user');
$password = Config::read('db.password');
self::$instance = new PDO($dsn, $user, $password);
}
public final static function getInstance(){
// Singleton daha önceden obje çağırıldıysa var olan instance'den yürü
if (!isset(self::$instance)){
$object = __CLASS__;
self::$instance = new $object;
}
return self::$instance;
}
public function query($sql) {
$STH = self::$instance->query($sql);
$STH->setFetchMode(PDO::FETCH_OBJ);
return $STH->fetch();
}
}
Config::write('db.type', 'odbc');
Config::write('db.host', 'localhost');
Config::write('db.port', '');
Config::write('db.dbname', '');
Config::write('db.user', '');
Config::write('db.password', '');
$sql = "SELECT count(filename) FROM VERSION";
$dbh = new DamraKOC();
$result = $dbh->query($sql);
print_r($result);
?>