我的库文件中有一个mysqli错误{ERROR :: mysqli_fetch_assoc()期望参数1为mysqli_result,null给定}

时间:2017-07-31 03:57:01

标签: php codeigniter mysqli codeigniter-2 codeigniter-3

我的库文件ERROR :: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given中有一个mysqli错误,任何人帮我解决它

我的安装程序文件:

public function __construct()
    {
        $CI = &get_instance();
        $CI->load->database();
        if ($CI->db->database == '') {
            header('location:install/');
        } else {
            //query from installer tbl
            $installer = mysqli_query('SELECT installer_flag FROM installer');
            $item = mysqli_fetch_assoc($installer);
            $flag = $item['installer_flag'];
            // if installer_flag = 0
            if ($flag == 0) {
                // make it 1
                mysqli_query('UPDATE installer SET installer_flag=1 WHERE id=1');
                if (is_dir('install')) {
                    header('location:install/success.php');
                }
            }
            //run this code
            //else nothing
        }
    }

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

2 个答案:

答案 0 :(得分:3)

如果您使用CI,则使用其内置函数来获取结果

$query = $this->db->query('SELECT installer_flag FROM installer');
foreach ($query->result_array() as $row)
{
   echo $row['title'];
}

答案 1 :(得分:1)

第一名: mysqli_query预计两个参数第一个参数是connection object第二个参数是sql query

示例:

mysqli_query($connection_object,$query);

Codeingniter:

$result = $this->db->query('SELECT installer_flag FROM installer')->result();
print_r($result);