Czy ktoś może pomóc jak zrobić tak aby można było pobierać dane w ten sposów
Kod
$user = $DB->select('users', array('username','=','tomek')) or die(mysql_error());
przy kodzie ponieżej,Kod
class DB {
private $_pdo,
$_query,
$_error = false,
$_results,
$_count = 0;
public static function getInstance() {
if(!isset(self::$_instance)) {
self::$_instance = new DB();
}
return self::$_instance;
}
public function action($action, $table, $where = array()) {
if (count($where) == 3) {
$operators = array('=','>','<','>=','<=',);
$field = $where[0];
$operator = $where[1];
$value = $where[2];
if (in_array($operator, $operators)){
$sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";
}
}
return false;
}
public function get($table, $where){
return $this->action('SELECT *', $table, $where);
}
private $_pdo,
$_query,
$_error = false,
$_results,
$_count = 0;
public static function getInstance() {
if(!isset(self::$_instance)) {
self::$_instance = new DB();
}
return self::$_instance;
}
public function action($action, $table, $where = array()) {
if (count($where) == 3) {
$operators = array('=','>','<','>=','<=',);
$field = $where[0];
$operator = $where[1];
$value = $where[2];
if (in_array($operator, $operators)){
$sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";
}
}
return false;
}
public function get($table, $where){
return $this->action('SELECT *', $table, $where);
}
///////////, a nie tak
$user = DB::getInstance()->select('username', array('username','=','tomek'));
bez tego db::getInstance
dzięki