Tworze sobie taką klase, która ułatwi mi działanie na bazie danych. Na początku tworzyła automatycznie zapytania itp. Osobno łączyłem się z bazą (via mysqli), osobno tworzyłem zapytanie (moją klasą). Jednak chciałem to połączyć, więc rozrzeszyłem klase mysqli o moją klase.
<?php class DBManager extends mysqli { private $table; private $whereClause; private $limit; public $connection; function __construct($host, $user, $pass, $base){ $this->connection = new mysqli($host, $user, $pass, $base); return $this; } public function from($table) { $this->table = $table; return $this; } public function where($clause) { $this->whereClause = $clause; return $this; } public function limit($limit) { $this->limit = $limit; return $this; } public function fields() { return $this; } public function select() { $query .= " WHERE {$this->whereClause}"; } $query .= " LIMIT {$this->limit}"; return $query; } public function update() { return $query; } public function delete() { $query = "DELETE FROM {$this->table} WHERE {$this->whereClause}"; return $query; } public function add() { return $query; } } $db = new DBManager("localhost", "root", "", "test"); $query = $db->from("posts")->where("id=4")->limit(1)->select("id", "title"); if (mysqli_connect_errno()) { } if ($result = $db->connection->query($query)) { while ($obj = $result->fetch_object()) { "; } $result->close(); } $db->connection->close(); ?>
I niby wszystko fajnie działa, ale w metodzie "select" ten fragment kodu nie jest wykonywany:
$query .= " WHERE {$this->whereClause}"; } $query .= " LIMIT {$this->limit}";
Tak jakby $this->limit była pusta. A nie jest! Nadmienię, że wcześniej działało

To już wszystko śmiga. Totalnie nie mam pojęcia ocb.
$a = $this->whereClause; $query .= " WHERE {$this->whereClause}"; } $a = $this->limit; $query .= " LIMIT {$this->limit}";
Jeżeli ktoś ma jakieś pomysły, to śmiało walić

Pozdrawiam!