Php MySQLI Bind_param查询未返回结果

Php MySQLI Bind_param查询未返回结果,php,mysql,arrays,mysqli,Php,Mysql,Arrays,Mysqli,我正在尝试获取我编写的这个函数,以从MySQL表返回一些数据。这是我的功能 function getCompInfoIDS($id) { global $mysqli; $query = " Select computers.asset, computers.serial, rooms.building_id, rooms.id, computers.assigned_person, computers.computer_name, computers

我正在尝试获取我编写的这个函数,以从MySQL表返回一些数据。这是我的功能

function getCompInfoIDS($id) {
    global $mysqli;
    $query = "
Select
  computers.asset,
  computers.serial,
  rooms.building_id,
  rooms.id,
  computers.assigned_person,
  computers.computer_name,
  computers.sticker,
  operating_systems.manufacturer_id,
  operating_systems.id As id1,
  computers.memory,
  computers.hard_drive,
  computers.department,
  computers.year_purchased,
  computers.po_cs_ca,
  computers.mac_address,
  computers.group_id,
  models.manufacturer_id As manufacturer_id1,
  models.id As id2,
  computers.type,
  computers.monitor_size
From
  computers Inner Join
  rooms On computers.room_id = rooms.id Inner Join
  operating_systems On computers.os_id = operating_systems.id Inner Join
  models On computers.model = models.id
 Where
  computers.id=?";
    $stmt = $mysqli -> prepare($query);
    $stmt -> bind_param('i',$id);
    $stmt -> execute();
    $stmt -> bind_result($asset, $serial, $building_id, $room_id, $assigned_person, $computer_name, $sticker, $os_type_id, $os_id, $memory, $hard_drive, $department, $year_purchased, $po_cs_ca, $mac_address, $group_id, $model_type_id, $model_id, $comp_type, $monitor_size, $date_modified);
    while($stmt -> fetch()){
        $computer_info = array($asset, $serial, $building_id, $room_id, $assigned_person, $computer_name, $sticker, $os_type_id, $os_id, $memory, $hard_drive, $department, $year_purchased, $po_cs_ca, $mac_address, $group_id, $model_type_id, $model_id, $comp_type, $monitor_size, $date_modified);         
    }

    return $computer_info;
该查询确实有效,我已经在phpmyadmin中使用多个ID对其进行了测试

我一直在跟着,一步一步地做,看看我做错了什么。我做了
echo“测试”在我的代码中的不同位置查看函数失败的位置,我无法在函数中找到一个失败点,只是没有用结果填充数组


我试着做了
echo$asset在我填充数组之前,没有显示任何内容,因此我不相信有任何数据实际被放入数组变量中

您必须添加
$stmt->store_result(),因此您的代码如下所示:

$stmt = $mysqli -> prepare($query);
$stmt -> bind_param('i',$id);
$stmt -> execute();
$stmt->store_result();
$stmt -> bind_result($asset, $serial, $building_id, $room_id, $assigned_person, $computer_name, $sticker, $os_type_id, $os_id, $memory, $hard_drive, $department, $year_purchased, $po_cs_ca, $mac_address, $group_id, $model_type_id, $model_id, $comp_type, $monitor_size, $date_modified);
while($stmt -> fetch()){
    $computer_info = array($asset, $serial, $building_id, $room_id, $assigned_person, $computer_name, $sticker, $os_type_id, $os_id, $memory, $hard_drive, $department, $year_purchased, $po_cs_ca, $mac_address, $group_id, $model_type_id, $model_id, $comp_type, $monitor_size, $date_modified);         
}

您的代码应该给出如下错误:

Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in C:\xampp\htdocs\... on line x
查询中选定列的数量与绑定结果的数量不同。在
SELECT
查询中只选择了20列,但是
bind\u result()
中有21个变量

查询中必须缺少一列。显然,对于您的
$date\u已修改的
变量。填写您的
选择要绑定的
$date\u modified
变量的正确查询