Pete
Pete

Reputation: 11

Zingchart PHP wrapper issue

I am attempting to set up Zingchart using the PHP wrapper module.

Server:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:    16.04
Codename:   xenial

Running as a VM under VMWare

I am receiving an error with the example code when calling the ZC->connect method.

Thus:

<HTML>
<HEAD>
<script src="zingchart.min.js"></script>
</HEAD>
<BODY>
<h3>Simple Bar Chart (Database)</h3>
<div id="myChart"></div>
<?php
include 'zc.php';
use ZingChart\PHPWrapper\ZC;

$servername = "localhost";
$username = "nasuser";
$password = "password";
$db = "nas";

$myQuery  = "SELECT run_time, time_total from stats";

// ################################ CHART 1 ################################
// This chart will use data pulled from our database
$zc = new ZC("myChart", "bar");
$zc->connect($servername, "3306", $username, $password, $db);
$data = $zc->query($myQuery, true);
$zc->closeConnection();
$zc->setSeriesData($data);
$zc->setSeriesText($zc->getFieldNames());
$zc->render();
?>
</BODY></HTML>

Error:

# php index.php
PHP Fatal error:  Uncaught Error: Class 'ZingChart\PHPWrapper\mysqli' not found in /var/www/html/zc.php:69
Stack trace:
#0 /var/www/html/index.php(22): ZingChart\PHPWrapper\ZC->connect('localhost', '3306', 'nasuser', 'password', 'nas')

Line 69 is:

$this->mysqli = new mysqli($host, $username, $password, $dbName, $port);

Running:

# php -m | grep -i mysql
mysqli
mysqlnd
pdo_mysql

Seems to indicate that I have the relevant packages installed. Indeed, if I attempt a normal PHP connection it works:

<?php
$servername = "localhost";
$username = "nasuser";
$password = "password";

$dbname = "nas";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * from stats limit 10;";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["stat_id"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

Output:

# php db.php
id: 1<br>id: 2<br>id: 3<br>id: 4<br>id: 5<br>id: 6<br>id: 7<br>id: 8<br>id: 9<br>id: 10<br>

Any ideas?

Thanks.

Upvotes: 0

Views: 209

Answers (1)

Druta Danut
Druta Danut

Reputation: 1

I've encountered the same problem! There's kind of problem with import on the mysqli. I changed the

$this->mysqli = new mysqli($host, $username, $password, $dbName, $port);

from ZC.php to

$this->mysqli = new \mysqli($host,$username,$password, $dbName, $port);

and worked.

Upvotes: 0

Related Questions