【发布时间】:2013-07-23 13:05:30
【问题描述】:
您好,我知道如何设置“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 部分,它总是出现某种错误:)
请帮忙, 谢谢
【问题讨论】:
-
究竟是什么错误?
-
发布的代码没有错误,它工作正常。问题是当我尝试插入“set_charset('utf8');”部分。如果我在
$this->db = new mysqli('127.0.0.1','root','pass','data');下尝试:$this->set_charset('utf8');它会给我“致命错误:调用未定义的方法 Homepage::set_charset()”
标签: php database class character-encoding