执行准备好的语句时出现以下错误
(2013) 在查询异常期间丢失与 MySQL 服务器的连接
我在发布之前检查了几乎所有关于该主题的问题,但找不到答案。所以请不要关闭。
我是 PHP 和 MYSQL 的新手,所以如果我犯了任何错误,请更正
我的代码:-
<?php
class sanitize_insert{
protected $prepared_stmt;
protected $db_sqli;
public function prepare_sanitized_insert($created_by)
{
if(!is_integer($created_by))
{
throw new InvalidArgException("Invalid argument(s) type. Expected integer(s)"); //to be defined
}
$query = "insert into requests_v(user_id,property_id,request_type,description,to_user_id,created_on,last_update_date,created_by,last_updated_by) values (?,?,?,?,?,now(),now(),8,8);";
if(!is_resource($this->db_sqli))
{
$this->db_sqli = mysqli_connect('host','user','password','dbname');
}
if(!$this->prepared_stmt = $this->dbh->prepare($query))
{
return false;
}
$this->prepared_stmt->bind_param('iiisi', $user_id, $property_id, $req_type, $desc,$to_id);
//$result = $this->db_sqli->execute($this->prepared_stmt);
return true;
}
public function execute_insert()
{
if(!is_object($this->prepared_stmt))
{
return false;
}
if(!is_resource($this->db_sqli))
{
$this->db_sqli = mysqli_connect('host','user','password','dbname');
}
$result = $this->prepared_stmt->execute();
return $result;
}
}
当我在方法“prepare_sanitized_insert”中执行准备好的语句时,它会在没有任何错误的情况下执行,但是当我在方法“execute_insert”中执行它时,它会失败并出现错误:-
(2013) 查询期间与 MySQL 服务器的连接丢失
执行对象之前准备好的语句的 var_dump
(mysqli_stmt)#4 (10) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int( 0) ["param_count"]=> int(5) ["field_count"]=> int(0) ["errno"]=> int(2013) ["error"]=> string(44) "失去连接到MySQL 服务器在查询期间" ["error_list"]=> array(1) { [0]=> array(3) { ["errno"]=> int(2013) ["sqlstate"]=> string(5) " HY000" ["error"]=> string(44) "Lost connection to MySQL server during query" } } ["sqlstate"]=> string(5) "HY000" ["id"]=> int(1) }
有人可以帮忙吗?