你得到了:可恢复的致命错误:类mysqli的对象无法转换为字符串

时间:2017-07-19 20:04:18

标签: php mysqli

我试过这个让它工作,我的一个朋友给了我这个,他无法弄清楚为什么它不起作用,这里给出的错误是代码

$stmt = $conn->prepare("SELECT clicks FROM affiliate WHERE ID ='$ID'");
$stmt->bind_param("i", "$conn");
$stmt->execute();
$stmt->bind_result($clicks); // Store the result in the $clicks variable

$clicks++; // Increment clicks
echo "$clicks";

我收到以下错误:

  

可恢复的致命错误:类mysqli的对象无法转换为字符串

1 个答案:

答案 0 :(得分:0)

正确的代码:

// Add `?` as a placeholder
$stmt = $conn->prepare("SELECT clicks FROM affiliate WHERE ID = ?");
// Bind $ID value to this `?` placeholder
$stmt->bind_param("i", $ID);

$stmt->execute();
$stmt->bind_result($clicks); // Store the result in the $clicks variable

$stmt->fetch();   // fetch result to fill `$clicks` with actual value

$clicks++; // Increment clicks
echo "$clicks";