简体   繁体   中英

Empty MySQLi prepared statement results

I'm just trying to select a specific row in the DB, but my result-set keeps coming up empty for some reason. However, when I run the query in HeidiSQL, I get results.

I'm stumped. I don't see anything particularly wrong with my code, and I've tried echoing $mysqli->error , but I don't have any errors. I have also added ini_set('display_errors', 'On'); error_reporting(E_ALL); ini_set('display_errors', 'On'); error_reporting(E_ALL); to my code.

$id =$_GET['sysid'];
$system_info = $mysqli->prepare("SELECT * FROM systems WHERE systems.id = ?");
$system_info->bind_param("i", $id);
$system_info->execute();
$system_info->store_result();
$system_info->bind_result($system_id, $system_name, $system_img);

You need to fetch the results.

$id = $_GET['sysid'];
$system_info = $mysqli->prepare("SELECT * FROM systems WHERE systems.id = ?");
$system_info->bind_param("i", $id);
$system_info->execute();
$system_info->bind_result($system_id, $system_name, $system_img);
$system_info->fetch();

Then you can use $system_id , $system_name and $system_img .

store_result will return you a mysqli_result object; it ignores bind_result .

$id = $_GET['sysid'];
$system_info = $mysqli->prepare("SELECT * FROM systems WHERE systems.id = ?");
$system_info->bind_param("i", $id);
$system_info->execute();
$result = $system_info->store_result();
list($system_id, $system_name, $system_img) = $result->fetch_array(MYSQLI_NUM);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM