Mysql query error - Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Object Given in

Asked

Viewed 9,463 times

0

Hello, I am making a query with PHP and am connecting to the normal database, however when returning the query and mounting in the table is returning the error: Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Object Given in on line 273 of my code.

On line 273 I have a While I am searching the array with the values and saving in a variable to organize in my table later. Follow line 273:

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

Follow now as 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’s the Mysql search I’m doing 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 me.

Thank you!

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 the mysqli_fetch_array, execute the mysqli_query and pass the result to the mysqli_fetch_array.
Second manual: https://secure.php.net/manual/en/mysqli-result.fetch-array.php

0

Voce should run the Query... in your case the mysql_fetch_array is coming empty as 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
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.