Error: Call to a member function fetch_assoc() on boolean in C:\wamp64\www\glpi\inc\dbmysql.class.php on line 318

Hi during the installation of GLPI (windows) i have an error. Error: Call to a member function fetch_assoc() on boolean in C:\wamp64\www\glpi\inc\dbmysql.class.php on line 318

GLPI SETUP

Update
Successful database connection

The database version seems correct (5.7.24) - Perfect !The database version seems correct (5.7.24) - Perfect !
Update of the premises

The new structure is hierarchical

If you were using a separator character you can specify it to automate the generation of the hierarchy.
You can also specify a base location that will include all generated locations.

Separation character

Root place

( ! ) Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in C:\wamp64\www\glpi\inc\dbmysql.class.php on line 318
( ! ) Error: Call to a member function fetch_assoc() on boolean in C:\wamp64\www\glpi\inc\dbmysql.class.php on line 318
Call Stack
# Time Memory Function Location
1 0.0001 405688 {main}( ) …\update.php:0
2 0.0587 1673248 showLocationUpdateForm( ) …\update.php:579
3 0.0678 1673664 display_old_locations( ) …\update.php:384
4 0.0686 1673712 DB->fetch_assoc( ) …\update.php:227

This is a part of the script

function prepare($query) {
      global $CFG_GLPI, $DEBUG_SQL, $SQL_TOTAL_REQUEST;

      $res = @$this->dbh->prepare($query);
      if (!$res) {
         // no translation for error logs
         $error = "  *** MySQL prepare error:\n  SQL: ".$query."\n  Error: ".
                   $this->dbh->error."\n";
         $error .= Toolbox::backtrace(false, 'DBmysql->prepare()', ['Toolbox::backtrace()']);

         Toolbox::logInFile("sql-errors", $error);
         if (class_exists('GlpitestSQLError')) { // For unit test
            throw new GlpitestSQLError($error);
         }

         if (($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE)
             && $CFG_GLPI["debug_sql"]) {
            $SQL_TOTAL_REQUEST++;
            $DEBUG_SQL["errors"][$SQL_TOTAL_REQUEST] = $this->error();
         }
      }
      return $res;
   }

   /**
    * Give result from a sql result
    *
    * @param mysqli_result $result MySQL result handler
    * @param int           $i      Row offset to give
    * @param type          $field  Field to give
    *
    * @return mixed Value of the Row $i and the Field $field of the Mysql $result
    */
   function result($result, $i, $field) {
      if ($result && ($result->data_seek($i))
          && ($data = $result->fetch_array())
          && isset($data[$field])) {
         return $data[$field];
      }
      return null;
   }

   /**
    * Number of rows
    *
    * @param mysqli_result $result MySQL result handler
    *
    * @return integer number of rows
    */
   function numrows($result) {
      return $result->num_rows;
   }

   /**
    * Fetch array of the next row of a Mysql query
    * Please prefer fetch_row or fetch_assoc
    *
    * @param mysqli_result $result MySQL result handler
    *
    * @return string[]|null array results
    */
   function fetch_array($result) {
      return $result->fetch_array();
   }

   /**
    * Fetch row of the next row of a Mysql query
    *
    * @param mysqli_result $result MySQL result handler
    *
    * @return mixed|null result row
    */
   function fetch_row($result) {
      return $result->fetch_row();
   }

   /**
    * Fetch assoc of the next row of a Mysql query
    *
    * @param mysqli_result $result MySQL result handler
    *
    * @return string[]|null result associative array
    */
line 318 -   function fetch_assoc($result) {
                   return $result->fetch_assoc();
                   }

   /**
    * Fetch object of the next row of an SQL query
    *
    * @param mysqli_result $result MySQL result handler
    *
    * @return object|null
    */
   function fetch_object($result) {
      return $result->fetch_object();
   }

   /**
    * Move current pointer of a Mysql result to the specific row
    *
    * @param mysqli_result $result MySQL result handler
    * @param integer       $num    Row to move current pointer
    *
    * @return boolean
    */
   function data_seek($result, $num) {
      return $result->data_seek($num);
   }

   /**
    * Give ID of the last inserted item by Mysql
    *
    * @return mixed
    */
   function insert_id() {
      return $this->dbh->insert_id;
   }

   /**
    * Give number of fields of a Mysql result
    *
    * @param mysqli_result $result MySQL result handler
    *
    * @return int number of fields
    */
   function num_fields($result) {
      return $result->field_count;
   }

   /**
    * Give name of a field of a Mysql result
    *
    * @param mysqli_result $result MySQL result handler
    * @param integer       $nb     ID of the field
    *
    * @return string name of the field
    */
   function field_name($result, $nb) {
      $finfo = $result->fetch_fields();
      return $finfo[$nb]->name;
   }

   /**
    * List tables in database
    *
    * @param string $table table name condition (glpi_% as default to retrieve only glpi tables)
    *
    * @return mysqli_result list of tables
    *
    * @deprecated 9.3
    */
   function list_tables($table = "glpi_%") {
      Toolbox::deprecated('list_tables is deprecated, use listTables');
      return $this->query(
         "SELECT TABLE_NAME FROM information_schema.`TABLES`
             WHERE TABLE_SCHEMA = '{$this->dbdefault}'
                AND TABLE_TYPE = 'BASE TABLE'
                AND TABLE_NAME LIKE '$table'"
      );
   }

   /**
    * List tables in database
    *
    * @param string $table Table name condition (glpi_% as default to retrieve only glpi tables)
    * @param array  $where Where clause to append
    *
    * @return DBmysqlIterator
    */
   function listTables($table = 'glpi_%', array $where = []) {
      $iterator = $this->request([
         'SELECT' => 'TABLE_NAME',
         'FROM'   => 'information_schema.TABLES',
         'WHERE'  => [
            'TABLE_SCHEMA' => $this->dbdefault,
            'TABLE_TYPE'   => 'BASE TABLE',
            'TABLE_NAME'   => ['LIKE', $table]
         ] + $where
      ]);
      return $iterator;
   }

   public function getMyIsamTables() {
      $iterator = $this->listTables('glpi_%', ['engine' => 'MyIsam']);
      return $iterator;
   }

   /**
    * List fields of a table
    *
    * @param string  $table    Table name condition
    * @param boolean $usecache If use field list cache (default true)
    *
    * @return mixed list of fields
    */
   function list_fields($table, $usecache = true) {
      static $cache = [];

      if (!$this->cache_disabled && $usecache && isset($cache[$table])) {
         return $cache[$table];
      }
      $result = $this->query("SHOW COLUMNS FROM `$table`");
      if ($result) {
         if ($this->numrows($result) > 0) {
            $cache[$table] = [];
            while ($data = $result->fetch_assoc()) {
               $cache[$table][$data["Field"]] = $data;
            }
            return $cache[$table];
         }
         return [];
      }
      return false;

Hello @njannucci. Welcome to the forums.

These are English language forums, so please can you edit your post and rephrase your query in English?

1 Like

oh sorry, its better now

2 Likes

This error means that your database result contains false rather than a set of results. This generally means that the query has failed for some reason. Your code should check that the query has not returned false before trying to use the results from it, really.

You don’t show the code for the display_old_locations() function so it’s impossible to give any guidance on which specific query is failing, or why. One thing is to try the query, with values rather than parameters, in something like phpmyadmin, and see what you find there.

Sorry I didn’t understand what you mean in the second part…
Tomorrow I’ll send you the whole script…

Don’t send me anything, post it on the forum here so everyone can see it. But narrow it down to the bit that is throwing the error message.

If you look at the call trace:

Call Stack
 # Time Memory Function Location
 1 0.0001 405688 {main}( ) …\update.php:0
 2 0.0587 1673248 showLocationUpdateForm( ) …\update.php:579
 3 0.0678 1673664 display_old_locations( ) …\update.php:384
 4 0.0686 1673712 DB->fetch_assoc( ) …\update.php:227

You can see that the fetch_assoc() is being called by display_old_locations(). So you need to look in that function to see what it’s doing and how. Although as your error message is on line 318, not 227, I wonder if there’s more to the call stack than we can see.

The other bit was about testing the query. If you open your direct connection to the database admin tools and type in the query with the values you are using for testing, if there’s an error in the query you will see what that error is.

ok i’ll see, so there is the whole script on pastebin here : https://pastebin.com/crQ3bzGK

update : it was because a table was missing so i create it and its working thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.