0

I have a mysqli error in my library file ERROR :: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given any one help me to solve it

My Installer file:

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
        }
    }

Error: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given

Aaron Fahey
  • 699
  • 1
  • 7
  • 20
Muhammad Ahmed
  • 100
  • 1
  • 11
  • mysqli_query expects two parameter one is connection object another one query – JYoThI Jul 31 '17 at 04:06
  • ok let me try this – Muhammad Ahmed Jul 31 '17 at 04:08
  • 1
    Possible duplicate of [mysqli\_fetch\_array()/mysqli\_fetch\_assoc()/mysqli\_fetch\_row() expects parameter 1 to be resource or mysqli\_result, boolean given](https://stackoverflow.com/questions/2973202/mysqli-fetch-array-mysqli-fetch-assoc-mysqli-fetch-row-expects-parameter-1) – always-a-learner Jul 31 '17 at 04:12

2 Answers2

3

if you are using CI then use its inbuilt functions to get the result

$query = $this->db->query('SELECT installer_flag FROM installer');
foreach ($query->result_array() as $row)
{
   echo $row['title'];
}
Exprator
  • 26,992
  • 6
  • 47
  • 59
1

1st : mysqli_query expects two parameter first parameter is connection object second parameter is sql query

example :

mysqli_query($connection_object,$query);

Codeingniter :

$result = $this->db->query('SELECT installer_flag FROM installer')->result();
print_r($result);
JYoThI
  • 11,977
  • 1
  • 11
  • 26