class MySQL {
public $link = null;
public function conn() {
$cfg = array(
'host'=>'localhost',
'user'=>'root',
'password'=>'',
'db'=>'test',
'charset'=>'utf8',
);
$this->link = mysqli_connect($cfg['host'] , $cfg['user'] , $cfg
['password'],$cfg['db']);
}
public function query($sql) {
return mysqli_query($this->link,$sql);
}
public function getAll($sql) {
$rs = $this->query($sql);
$data = array();
while($row = mysqli_fetch_assoc($rs)) {
$data[] = $row;
}
return $data;
}
}
$db = new MySQL();
$db->conn();
$user = $db->getAll('select * from user');
var_dump($user)