MySQL query error - Warning: mysqli_fetch_array () expects parameter 1 to be mysqli_result, object given in [duplicate]

0

Hello, I am doing a query with PHP and I am connecting to the normal database, but when I return the query and mount in the table it is returning the error: Warning: mysqli_fetch_array () expects parameter 1 to be mysqli_result, object given in in line 273 of my code.

On line 273 I have a While I'm fetching the array with the values and saving in a variable to arrange in my table afterwards. Follow line 273:

while ($result = mysqli_fetch_array($link, $query)) {

Here's how the connection is being made:

define("HOST","hostmysql"); define("USER","usuario"); define("PASSWORD","senha"); define("DBNAME","nomeDB"); $link = mysqli_connect(HOST,USER,PASSWORD) or die("Erro ao conectar ao banco de dados");

Here is the MySQL search I'm doing together with While again:

'$query = "SELECT id, tipo, numero, ano, descricao, data, horario, arquivos, cadastro, status FROM lici ORDER BY id DESC";

while ($result =  mysqli_fetch_array($link, $query)) {'

I hope this helps to help me.

Thank you!

    
asked by anonymous 03.08.2018 / 16:48

2 answers

0

The structure for mysql queries in php is as follows:

<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
$result = mysqli_query($link, $query);

/* numeric array */
$row = mysqli_fetch_array($result, MYSQLI_NUM);
printf ("%s (%s)\n", $row[0], $row[1]);  

/* associative array */
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);  

/* associative and numeric array */
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);  

/* free result set */
mysqli_free_result($result);

/* close connection */
mysqli_close($link);
?>

Before mysqli_fetch_array , run mysqli_query and pass result to mysqli_fetch_array . Second handbook: link

    
03.08.2018 / 16:52
0

You should run Query ... in your case mysql_fetch_array is coming empty, because the query was not executed.

Remember to close the connection after the query.

example:

$query= "SELECT id, tipo, numero, ano, descricao, data, horario, arquivos, cadastro, status FROM lici ORDER BY id DESC";
mysqli_query($link, $query);
if(mysqli_query($link, $query)){
    $result =  mysqli_fetch_array($link, $query);
    mysqli_close($link);
}else{
    die("Error:".$link->error);
    mysqli_close($link);
}
while ($result) {
    //restante do codigo
}
    
03.08.2018 / 17:31