php - Query doesn't work on my Raspberry Pi 2B

317

I'm trying to get my raspberry working like a webserver.

It all works, except the queries of my mysql database. The values are correct, the query is correct and my database works fine.

But when I want to get information from my database with PHP it gives an empty result.

The code:

<?php

$dbCon = new mysqli($servername, $username, $password, $database);

$Query = "SELECT * FROM `machineuptime`";

if($stmt = $dbCon->prepare($Query))
{
    $stmt->execute();

    $result = $stmt->get_result();

    while($row = $result->fetch_assoc())
    {
        $ArrayData2[] = $row;
    }
}

echo "this is de first row of the array: " . $ArrayData2[0]['ID'] . ". Thats nice!";
?>

the result:

this is de first row of the array: . Thats nice!

Even when I use the query in phpmyadmin, it gives the values back, so the Query isn't wrong.

So how can I solve this issue?

Edit:

The error that I get is.

Fatal error: Call to undefined method mysqli_stmt::get_result() in /var/www/html/Stramit/index.php on line 59
238

Answer

Solution:

you don't close the query at:

$Query = "SELECT * FROM `machineuptime`;

change it to:

$Query = "SELECT * FROM `machineuptime`";

also for the error

Fatal error: Call to undefined method mysqli_stmt::get_result() in /var/www/html/Stramit/index.php on line 59

look at this answer.

Look at the user notes for http://php.net/manual/en/mysqli-stmt.get-result.php

It requires mysqlnd driver.Make sure you have that driver installed. If you do not have them installed use BIND_RESULT & FETCH

uncommented the extension=php_mysqli_mysqlnd.dll in php.ini; and restarted Apache2.2 and MySQL services. says it in the comment of the answer.

Here is the link to the driver: http://php.net/manual/en/book.mysqlnd.php

after you have installed it you should be able to use$stmt->get_result(); ofcourse reboot your raspberry pi.

Note: your php version must be above php 5.3.0

People are also looking for solutions to the problem: php - Why can't I view the image after force downloading?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.