调用未定义的方法mysqli_stmt :: bindParam()

时间:2017-09-07 09:30:42

标签: php mysqli

正如标题所示,我尝试了不同的设置,还有其他一些问题。

$conn = new mysqli("localhost","root","root","site_db");

foreach($webdesigns as $designer){

  $whmcs_id = $designer['id'];
  $email = $designer['email'];
  $portfolio = json_encode($designer['designs'],JSON_FORCE_OBJECT);

  $stmt = $conn->prepare("INSERT INTO partners (whmcs_id,email,portfolio) VALUES (?, ? , ?)");

  $stmt->bindParam(1, $whmcs_id);
  $stmt->bindParam(2, $email);
  $stmt->bindParam(3, $portfolio);
  echo $stmt->execute();

}

1 个答案:

答案 0 :(得分:1)

使用mysqli时它是bind_param 使用PDO时它是bindParam 使用MySQLi bind_param,您必须设置变量类型,1,2,3不是变量类型 点击此处查看变量类型:http://php.net/manual/en/mysqli-stmt.bind-param.php#refsect1-mysqli-stmt.bind-param-parameters

$conn = new mysqli("localhost","root","root","site_db");

foreach($webdesigns as $designer){

  $whmcs_id = $designer['id'];
  $email = $designer['email'];
  $portfolio = json_encode($designer['designs'],JSON_FORCE_OBJECT);

  if($stmt = $conn->prepare("INSERT INTO partners (whmcs_id,email,portfolio) VALUES (?, ? , ?)")){

      $stmt->bind_param("iss", $whmcs_id,$email,$portfolio);

      if(!$stmt->execute()){
            print_r("Error : $conn->error");
       }
    } else{
        print_r("Error preparing: $conn->error");
    }
}