2016-01-22 38 views
-2

我试图让我的树莓像网络服务器一样工作。查询不适用于我的树莓派2B

这一切工作,除了我的mysql数据库的查询。值是正确的,查询是正确的,我的数据库工作正常。

但是,当我想从PHP数据库中获取信息时,它会给出一个空的结果。

代码:

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

结果:

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

即使当我使用查询在phpMyAdmin,它给人的值返回,所以查询是没有错的。

那么我该如何解决这个问题呢?

编辑:

,我得到的是错误。

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

即使我不,这个代码工作在我的笔记本... – Bart88

+1

尝试启用错误报告补充一点:'的error_reporting(E_ALL); ini_set('display_errors',-1);'到php部分的顶部 – BRoebie

+0

您没有结束您的查询与“ - 是一个错字,或者实际上在源?” –

回答

0

你不关闭查询:

$Query = "SELECT * FROM `machineuptime`; 

将其更改为:

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

也为错误

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

看看this answer.

请看用户注意事项http://php.net/manual/en/mysqli-stmt.get-result.php

它需要mysqlnd驱动程序。请确保安装了该驱动程序。如果您没有安装它们,请使用BIND_RESULT & FETCH

取消注释了extension = php_mysqli_mysqlnd.dll in php.ini;并重新启动Apache2.2和MySQL服务。在答案的评论中说。

这里是链接到驱动程序:http://php.net/manual/en/book.mysqlnd.php

您在安装后,你应该能够使用$stmt->get_result(); ofcourse重启树莓派。

注:您的PHP版本必须高于PHP 5.3.0

+0

有没有一种方法可以安装使用fetch_assoc的驱动程序? – Bart88

+0

它不是fetch_assoc它是get_result,我将为它添加链接。 – BRoebie

+0

如果您有任何结果(好或不好)请回报。 – BRoebie