代码点火器:错误mysqli_query()需要至少2个参数,1给定,mysqli_fetch_assoc()期望参数1为mysqli_result,给定为null

时间:2016-10-10 12:48:59

标签: php codeigniter mysqli

目前,如果我正在对数据库进行查询以获取行值,则查询会正常运行,但我也会遇到此错误。

错误: mysqli_query()预计至少有2个参数,给定1个

错误: mysqli_fetch_assoc()期望参数1为mysqli_result,给定为null

我正在使用Code Igniter,这是我的代码:

$query1 = "select sum(vipnumber) as viptkt from buyers where buyer_eventid= $event_id";

        $queryResult1 = mysqli_query($query1);
     if (mysqli_fetch_assoc(mysqli_query($query1)) == NULL)
     {
         $tkt = $this->db->query("SELECT (event.totalviptickets - SUM( buyers.vipnumber )) AS remainingviptickets FROM buyers JOIN 
        event ON buyer_eventid =$event_id WHERE event_id =$event_id;");
         return $tkt->result_array();
     }
     else {
         $tkt1 = $this->db->query("select sum(totalviptickets) as remainingviptickets from event where event_id = $event_id");

         return $tkt1->result_array();
     }

`

1 个答案:

答案 0 :(得分:-1)

在config中验证您的database.php:

如果 $db['default']['autoinit'] = FALSE;

使用 $this->load->database();加载您的连接;