简体   繁体   中英

I am trying to rerwrite this as a mysqli query but I keep getting an error

I wrote a query in PHP and mysql and it works fine and returns data I am just trying to re-write it as a Mysqli function.

This is what I come up with but I get a 500 error with the file.

if (mysqli_connect_errno()) {
    printf("Could not talk to the database: ", mysqli_connect_error());
    exit();
}
$query("SQL QUERY WORKS FINE");
$data = array();
if ($result = $con->query($query)) {
    $tempData = array();
    while ($row = $result->fetch_object()) {
        $tempData = $row;
        array_push($data, $tempData);
    }
    echo json_encode($myArray);
}
/* free result set */
$result->close();
$con->close();

First problem I see is that you are trying to json_encode a variable that does not exist. change $myArray to $tempData ?

If your debugging is turned off the error message would go into error_log saying undefined variable $myArray

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM