在下面的代码中,如果$get_artist是数据库中不存在的主键,那么绑定变量$artistid应该总是返回 0,对吗?但它没有,它总是什么都不返回,不是 0,什么都没有!为什么?
if (isset($_GET['artist']) && is_numeric($_GET['artist'])) {
$get_artist = (int)$_GET['artist'];
}
$sql = 'SELECT artist_id, name, legal_name, photo_basename
FROM artist
WHERE artist_id = ?';
$conn = connect('read');
$stmt = $conn->stmt_init();
$stmt->prepare($sql);
$stmt->bind_param('i', $get_artist);
$stmt->execute();
$stmt->store_result();
$num_rows = $stmt->num_rows;
$stmt->bind_result($artistid, $name, $legalname, $photo);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
// if $get_artist is an invalid primary key, it should echo 0, right?
echo $artistid;