Skip to content
Advertisement

PHP Fatal error: Uncaught Error: Call to undefined function mssqli_fetch_assoc()

I have a database table called BRANDS and,
one of the records, in the table, is called BRAND

Here’s my PHP code:

$db = mysqli_connect('127.0.0.1','root','','ecomm');
  if (mysqli_connect_errno()) 
  {
    echo 'DataBase connection was not successful. More details here: '.mysqli_connect_err();
    die();
  }
    
    // I run the query
    $sql ="SELECT * FROM brands ORDER BY brand";
    $brand = $db->query($sql);
    echo $brand;
    
    // and put results in associative array, in order to the results
    while($brands = mssqli_fetch_assoc($brand)) :
        echo($brands['brand']);
    endwhile;

What I get in return is the following error:

Fatal error: Uncaught Error: Call to undefined function mssqli_fetch_assoc()

Can you please tell me what am I doing wrong?

Advertisement

Answer

You have to use mysqli_fetch_assoc instead of mssqli_fetch_assoc

try this

$db = mysqli_connect('127.0.0.1','root','','ecomm');
if (mysqli_connect_errno()) 
{
  echo 'DataBase connection was not successful. More details here: '.mysqli_connect_err();
  die();
}

  // Run the query
  $sql ="SELECT * FROM brands ORDER BY brand";
  $brand = $db->query($sql);
  echo $brand;

  // and put results in associative array, in order to the results
  while($brands = mysqli_fetch_assoc($brand)) :
      echo($brands['brand']);
  endwhile;
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement