Select from MySQLi database with prepared statements using PHP

January 24, 2024


$query = "SELECT *
FROM items
WHERE deleted != 'y'
AND id = ?
LIMIT 1
";

$stmt = $mysqli -> prepare($query);
$stmt -> bind_param("s", $id);
$stmt -> execute();
$result = $stmt -> get_result();

$num_rows = $result -> num_rows;

if($num_rows > 0){

$row = $result -> fetch_assoc();

echo $row['id'] . ' < br > ';
echo $row['title'] . ' < br > ';

} else {

echo 'There are no results.';

}


Comments

There are no comments.


Comment on this Article

Your email address will never be published. Comments are usually approved within an hour or two. (to prevent spam)