嗨,我知道如何设置“set_charset('utf8');” 风格:
$db = new mysqli('127.0.0.1','root','pass','data') or die ('error with connection');
$db->set_charset('utf8');
但现在我想用这样的类来做到这一点:
class Core {
protected $db, $result;
private $rows;
public function __construct(){
$this->db = new mysqli('127.0.0.1','root','pass','data');
}
public function query ($sql){
$this->result = $this->db->query($sql);
}
public function rows(){
for($x =1; $x<= $this->db->affected_rows; $x++){
$this->rows[] = $this->result->fetch_assoc();
}
return $this->rows;
}
}
但我无法创建这个 db set charset 部分,它总是某种错误:)
请帮忙,谢谢