0

I've looked everywhere but can't find it, so here goes the bit of php code that just won't work:

$link = mysqli_connect(DB_SERVER, username, password, database);
$link2 = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if(!$link){
    echo "error link";
}else{
    $query = "SELECT * FROM `user`";
    $result = mysqli_query($link, $query);
    if(!$result){
        echo "error ".mysqli_error($link);
        return;
    }
    while($row = mysqli_fetch_array($result)){
        //do things
    }
}

The if(!$result) doesn't catch anything, and yet, I keep getting "mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in" errors on the "while" line.

Why?

--EDIT:

A var_dump of $result returns:

object(mysqli_result)#3 (5) {
  ["current_field"]=>
  int(0)
  ["field_count"]=>
  int(9)
  ["lengths"]=>
  NULL
  ["num_rows"]=>
  int(588)
  ["type"]=>
  int(0)
}

$mysqli_error($link) is empty

And I also don't think this is a duplicate, I've looked all over StackOverflow and other forums for this and all of them fail to solve my problem, saying that $result must be returning false due to a failure of the query or something, which is clearly not the case, as shown above.

ekad
  • 14,436
  • 26
  • 44
  • 46
Pedro Carvalho
  • 565
  • 1
  • 6
  • 26
  • Otherwise `var_dump` your `$result` variable, and print out `mysqli_error()` regardless of it. – mario Jul 01 '15 at 12:51
  • Editted to show that. – Pedro Carvalho Jul 01 '15 at 13:07
  • Well then it's probably not a duplicate. Still unanswerable though. The warning doesn't match up with your code and the actual variable contents. Show the real code. – mario Jul 01 '15 at 14:14
  • That is the entire code; the only thing that comes after the "while" is an echo, the only thing that comes before the $link is whether the file exists. However, removing the $link2 variable solved it. – Pedro Carvalho Jul 01 '15 at 14:16
  • Probably there is something happening in `// do things` that is modifying `$result`, but we can't tell without seeing your code. Does that loop execute at all? Have you put a diagnostic in the loop to see? – Andy Lester Jul 01 '15 at 16:37

0 Answers0