Hello am trying to access the pdo object returned from DatabaseConnection class in Database class but its giving me difficulty am using singleton pattern .please help
class DatabaseConnection {
protected static $_instance = NULL;
public static $pdo;
private function __construct() {
try {
$this->pdo = new PDO ( 'mysql:host=' . Configuration::getConfiguration ( 'mysql/host' ) . ';dbname=' . Configuration::getConfiguration ( 'mysql/databaseName' ), Configuration::getConfiguration ( 'mysql/user' ), Configuration::getConfiguration ( 'mysql/password' ) );
} catch ( PDOException $e ) {
echo 'woops !connection to the server failed.' . $e->getMessage ();
}
}
public static function getConnectionInstance() {
if (! isset ( self::$_instance )) {
self::$_instance = new DatabaseConnection ();
}
return self::$_instance;
}
}/*end od DatabaseConnection*/
class Database implements DatabaseInterface {
public static function select($fields = array(), $table, $where = array())
{
$fields = '`' . implode ( '`,`', $fields ) . '`';
$fix = '';
$x = 1;
foreach ( $where as $tableField => $value ) {
$fix .= "`{$tableField}` = '{$value}'";
if ($x < count ( $where )) {
$fix .= ' AND ';
}
$x ++;
}
$sql = "SELECT {$fields} FROM `{$table}` WHERE {$fix} ";
if (DatabaseConnection::$pdo->prepare ( $sql )) {
echo 'prepared';
}
return false;
}
}