如何选择多个查询并检索它们

时间:2014-02-22 13:00:07

标签: php mysqli

当我检索两个表时出现错误。我的代码有什么问题?我不知道如何解决这个问题

    <?php
include ('includes/config.php');

$mysqli = new mysqli(DB_SERVER, DB_UNAME,DB_PASSWD,DB_NAME);
if(!$mysqli){
  throw new Exception($mysqli->connect_error, $mysqli->connect_errno);
}

$jqry = $mysqli->prepare("SELECT time FROM table_time ORDER BY time");
if (!$jqry){

  throw new Exception($mysqli->error);

}
$jqry->execute();
$jqry->bind_result($time);
$jqry->store_result();

$times = array();

while ($jqry->fetch()){

        $times[] = $time;

}
$jqry->close();

$gqry = $mysqli->prepare("SELECT table_group.group FROM table_group.table_group ORDER BY group");
if(!$gqry){

  throw new Exception($gqry->error);
}
$gqry->execute();
$gqry->bind_result($group);
$gqry->store_result();

$groups = array();

while ($gqry->fetch()){

  $groups[] = $group;
}


?>

这是我得到的错误:

  

注意:尝试在第31行的C:\ xampp \ htdocs \ ~Jeremiah \ system5 \ joborder.php中获取非对象的属性

     

致命错误:C:\ xampp \ htdocs \ ~Jeremiah \ system5 \ joborder.php中未捕获的异常'Exception':31堆栈跟踪:#0 {main}抛出

1 个答案:

答案 0 :(得分:0)

在第31行无效之前

你的SQL。尝试直接对db执行它。

来自手册:

mysqli_prepare() returns a statement object or FALSE if an error occurred. 

...那就是为什么我们不在开发环境中压制通知! :)