我正在尝试将我的 sql 类转换为更合适的类。类构造函数如下所示:
class sql{
private $db_name = CONFIG_DB_NAME;
private $db_user = CONFIG_DB_USER;
private $db_pass = CONFIG_DB_PASS;
private $db_host = CONFIG_DB_HOST;
private $use_pconnect = CONFIG_DB_USEP;
function __construct(){
if($this->use_pconnect){
$connection = new mysqli('p:'.$this->db_host, $this->db_user, $this->db_pass, $this->db_name);
}else{
$connection = new mysqli($this->db_host, $this->db_user, $this->db_pass, $this->db_name);
}
if($connection->connect_errno){
$this->sql_handle_errors($connection->connect_error, __FILE__, __LINE__);
exit();
}
$this->connection = $connection;
// Set DB charset
if(!mysqli_set_charset($this->connection, CONFIG_CHARSET)){
$this->sql_handle_errors(mysqli_error($this->connection), __FILE__, __LINE__);
}
if(file_exists(PATH_LOGS.'sql.txt')){
$this->test_query = true;
}
}
}
$sql = new sql;
我正在测试的结果如下所示:
$result = $sql->connection->prepare("SELECT * FROM admin WHERE id = :id LIMIT 1");
$result->bind_param(':id', '1');
$result->execute();
$result->store_result();
$result->fetch();
它说的 bind_param 函数找不到。有什么理由吗?谢谢。