-2

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
Mike Szyndel
  • 9,787
  • 7
  • 41
  • 61
Bart88
  • 133
  • 1
  • 2
  • 9

1 Answers1

0

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

Community
  • 1
  • 1
BRoebie
  • 374
  • 3
  • 13