-1

My connection to my database show some error

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in /---/---/---/function/function.php on line 10

<?php
$connection = mysqli_connect("localhost","root","password");

//getting the categories

function getCats(){
global $connection;
    $get_cats = "select * from category";
    $run_cats = mysqli_query($connection, $get_cats);
    while ($row_cats = mysqli_fetch_array($run_cats)){
        $cat_id = $row_cats['cat_id'];
        $cat_title = $row_cats['cat_title'];

    echo"<li><a href='#'>$cat_title</a></li>";
    }
}
?>
Dharman
  • 26,923
  • 21
  • 73
  • 125
Abeth
  • 1
  • 2
  • Does it connect successfully? Not too familiar with `mysqli` does it require `db` name on connection? – chris85 Aug 15 '15 at 15:44
  • Why not `var_dump($run_cats);` to debug the issue? It's somewhat unlikely that `mysqli_query` returns a *string* rather than a boolean or object. Show the real/current code. – mario Aug 15 '15 at 15:47
  • The connection is successfully but it show the error. That is the real code – Abeth Aug 15 '15 at 15:57

1 Answers1

1

Your title refers to a boolean, the error text to a string.

The first would be caused by a SQL error or connection error of some kind, which you can track by retrieving the MySQL error code and message. The second might have been caused by erroneously supplying the query text instead of the query result (i.e, run_cats instead of get_cats).

LSerni
  • 53,899
  • 9
  • 63
  • 106