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";
?> 

Recommended Answers

All 3 Replies

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.

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

You're welcome!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.