Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Obiektowe wbijanie rekordów
login800
post 7.01.2015, 00:38:29
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 28.09.2013

Ostrzeżenie: (0%)
-----


Witajcie

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);
    }


///////////, a nie tak

$user = DB::getInstance()->select('username', array('username','=','tomek'));

bez tego db::getInstance

dzięki

Ten post edytował login800 7.01.2015, 00:44:16
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
com
post 7.01.2015, 00:48:19
Post #2





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

Ostrzeżenie: (0%)
-----


  1. $user = DB::getInstance();
  2. $user->select('username', array('username','=','tomek'));

a tak sie nie dało?
Go to the top of the page
+Quote Post
login800
post 7.01.2015, 02:17:17
Post #3





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 28.09.2013

Ostrzeżenie: (0%)
-----


Tak, a zupełnie bez tego getinstance ?
Go to the top of the page
+Quote Post
Pyton_000
post 7.01.2015, 06:55:56
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Nie, a w czym Ci to przeszkadza?
Go to the top of the page
+Quote Post
com
post 7.01.2015, 23:46:35
Post #5





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

Ostrzeżenie: (0%)
-----


skoro używasz singletona to musisz go jakoś zracjonalizować, to tak jakbyś chciał użyć klasy bez deklaracji że jej używasz, nie miało to by sensu. A jeśli robisz więcej niż jedną operacja do tej klasy a zakłada że tak to robisz tak jak Ci napisałem
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.07.2025 - 23:35