PHPの問題があるかもしれませんが、これは簡単なことですが、本当に助けてください!PHP準備されたSELECT変数を使用したMySQLiの問題
私の関数はmysqliカウントを行いますが、sqlがうまく動作し、エラーがなくても、バインドされる$ countパラメータは変更されません。
機能:
function itemsCount ($conn, $list_id) {
$count = 0;
if (!($stmt = $conn->prepare("SELECT count(uid) FROM collection.user_list_item WHERE list_id = ?"))) {
echo "Prepare failed: " . $mysqli->error;
}
if (!($stmt->bind_param('i', $list_id))) {
echo "Bind failed: " . $stmt->error;
}
if (!($stmt->execute())) {
echo "Execute failed: " . $stmt->error;
}
if (!($stmt->bind_result($count))) {
echo "Bind failed: " . $stmt->error;
}
echo $count;
$stmt->close();
return $count;
}
そしてコール:
public function doAdd ($conn, $list_id, $item_id) {
if ($this->itemsCount($conn, $list_id) < 20) {
...do stuff ...
}
}
申し訳ありませんが、コードは非常に素晴らしいではありませんが、正しい方向に私を指すよう助けてください!
実際に行を取得するには、 '$ stmt-> bind_result()'の後に '$ stmt-> fetch()'を呼び出す必要があります。 –
ありがとう@MichaelBerkowski!私は今、とても馬鹿だと感じています... –