0

Hi all, I'm facing this error while following a tutorial.

Warning: mysqli_result::fetch_array() expects parameter 1 to be integer, string given in C:\xampp\htdocs\client\login.php on line 12
[]
Here is my php

<?PHP 
    include_once("connection.php"); 
if( isset($_GET['format']) && $_GET['format'] == "json" )  { 

        $query = "SELECT * FROM tbl_client " ;

        $result = mysqli_query($conn, $query)
          or die("Error: ".mysqli_error($conn));

        $myArray = array();

        while($row = $result -> fetch_array('MYSQL_ASSOC')) {
                    $myArray[] = $row;
       }
       echo json_encode($myArray);

        $result->close();

                exit; 
            } 

echo "add <i>?format=json</i> the end of the URL";
?> 
2
Contributors
3
Replies
14
Views
1 Year
Discussion Span
Last Post by cereal
1

Hi,

look at the manual: http://php.net/manual/en/mysqli-result.fetch-array.php

The argument must be a constant, in your case MYSQL_ASSOC without the quotes, the constant in this case is an integer and his value is 1, for MYSQL_BOTH instead is 3, so you could write:

$result->fetch_array(MYSQL_ASSOC);

# or

$result->fetch_array(1);

and get the same result type.

0

Thank you for the answer , I have being trying out for a few hours now . You are a lifesaver.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.