PHP + Mysqli没有显示结果

时间:2015-02-26 20:58:35

标签: php mysqli mariadb

我有PHP和mysqli的问题,我不知道如何解决。我试图查询数据库并将结果作为关联数组,但我似乎无法实现。当我访问此页面时,我得到一个空白屏幕,里面没有任何内容。

这是我的代码:

$link = mysqli_connect("localhost", "dash_user", "DASH_dash", "dashboard");
$query = "SELECT * FROM system_settings";

if ($result = mysqli_query($link, $query)) {

/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
printf ("%s (%s)\n", $row["install_date"], $row["export_reports_enabled"]);
}

/* free result set */
mysqli_free_result($result);

我确实从PHP的库中得到了它。我也试过这个:

<?php
$ddb_database = "dashboard";
$ddb_host = "localhost";
$ddb_user = "dash_user";
$ddb_pass = "DASH_dash";
$ddb_port = "3306";

$ddb=mysqli_connect("$ddb_host", "$ddb_user", "$ddb_pass", "$ddb_database", "$ddb_port");

if (!$ddb)
    {
    die("MySQL Dashboard DB connect ERROR:  " . mysqli_error('mysqli'));
    }

if ($result = mysqli_query($ddb,$stmt))
{
$result = mysqli_query($ddb, $stmt);
$row_cnt = mysqli_num_rows($result);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$install_date =             $row["install_date"];
$messaging_enabled =        $row['messaging_enabled'];
$tasks_enabled =            $row['tasks_enabled'];
$alerts_enabled =           $row['alerts_enabled'];
$export_reports_enabled =   $row["export_reports_enabled"];
mysqli_free_result($result);
}

echo "Install date: $install_date";
echo "Export reports: $export_reports_enabled";
echo "Number of rows: $row_cnt";

但我仍然无法到达任何地方。没有连接错误。

数据库看起来像这样:

MariaDB [dashboard]> SELECT * FROM system_settings;
+--------------+-------------------+---------------+----------------+------------------------+
| install_date | messaging_enabled | tasks_enabled | alerts_enabled | export_reports_enabled |
+--------------+-------------------+---------------+----------------+------------------------+
| 2015-02-23   | N                 | N             | N              | N                      |
+--------------+-------------------+---------------+----------------+------------------------+
1 row in set (0.00 sec)

我也理解Mysqli也与MariaDB(我的数据库引擎)兼容。这可能是我问题的原因吗?

1 个答案:

答案 0 :(得分:-1)

如果这是您的完整代码(在第一部分中),则错过了属于}

if
$link = mysqli_connect("localhost", "dash_user", "DASH_dash", "dashboard");
$query = "SELECT * FROM system_settings";

if ($result = mysqli_query($link, $query)) {

    /* fetch associative array */
    while ($row = mysqli_fetch_assoc($result)) {
        printf ("%s (%s)\n", $row["install_date"], $row["export_reports_enabled"]);
    }

    /* free result set */
    mysqli_free_result($result);
}

我无法确定这是否符合您的意图,因此您可能需要向上移动支架。

如果正确缩进,调试代码会更容易。

编辑:看一下this的mariaDB问题。

另外,如评论中所述,turn on报告错误报告,以了解最新情况。

ini_set('error_reporting', E_ALL);