Bonjour,

Je n'arrive pas à faire fonctionner fetch_assoc(). J'ai le message d'erreur :
Fatal error: Call to a member function fetch_assoc() on a non-object in index.php on line 51
Pourtant pour le code je me suis basé sur cette page et il est donc sans problème.
https://arian.io/when-to-use-bind_re...sult-in-mysql/

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$mysqli = new mysqli($db_domain, $db_user, $db_password, $db_database) ;
if($stmt = $mysqli->prepare("SELECT * FROM user where 1 ")){
   /*
        Binds variables to prepared statement
 
        i    corresponding variable has type integer
        d    corresponding variable has type double
        s    corresponding variable has type string
        b    corresponding variable is a blob and will be sent in packets
   */
  /*
  $email = "myemal@free.fr" ;
  $stmt->bind_param('s',$email);
  */
   /* execute query */
   $stmt->execute();
 
   /* Store the result (to get properties) */
   $stmt->store_result();
 
   /* Get the number of rows */
   $num_of_rows = $stmt->num_rows;
   echo $num_of_rows;
 
   /* Get the result */
   $result = $stmt->get_result();
 
   while ($row = $result->fetch_assoc()) {
     echo 'Firstname: '.$row['user_firstname'].'<br>;';
   }
 
   /* free results */
   $stmt->free_result();
 
   /* close statement */
   $stmt->close();
}
Le echo $num_of_rows; me renvoie bien 3.

Quelqu'un a une idée ? J'ai l'impression que ça viendrait d'un problème de configuration du serveur.

Merci.