Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return DB::select('*')->from('users')->where("id",'=',$id);
- <?php
- class Db {
- private static $db;
- private static $host = 'localhost';
- private static $dbname = 'test';
- private static $charset = 'utf8';
- private static $username = 'root';
- private static $password = '';
- private $select;
- private $from;
- private $id;
- static function connect() {
- if(empty(self::$db)) {
- self::$db = new PDO("mysql:host=".self::$host.";dbname=".self::$dbname.";charset=".self::$charset,
- self::$username, self::$password);
- }
- return self::$db;
- }
- public function select($mark) {
- $this->select = 'SELECT ' . $mark;
- return $this;
- }
- public function from($table) {
- $this->from = ' FROM ' . $table;
- return $this;
- }
- public function where($id) {
- $this->where = ' WHERE id = ' . $id;
- return $this;
- }
- }
- class User extends Db {
- public function __toString() {
- return $this->viewUser();
- }
- public function viewUser() {
- return Db::select('*')->from('users')->where('1');
- }
- }
- $user = new User;
- echo $user->viewUser();
- print_r((array)$user->viewUser());
- и получился какой-то бред
- Array ( [Dbselect] => SELECT * [Dbfrom] => FROM users [Dbid] => [where] => WHERE id = 1 )
- $user = new User;
- $str = '';
- foreach((array)$user->viewUser() as $key) {
- $str = $str . $key;
- }
- echo $str;
Add Comment
Please, Sign In to add comment