I have a problem with PHP and mysqli that I don't know how to solve. I'm trying to query the DB and get the results as an associative array, but I can't seem to get there. When I access this page I get a blank screen with nothing in it.
This is my code:
$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);
I literally, got that from PHP's library. I also tried this:
<?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";
But I still do not get anywhere. There are no connection errors.
The DB looks like this:
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)
It is also my understanding that Mysqli is also compatible with MariaDB (my DB engine). Could that be the cause of my problem?