我正在尝试使用PHP包装器模块设置Zingchart。
服务器:
<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>
调用ZC-&gt; connect方法时,我收到示例代码错误。
因此:
# 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')
错误:
$this->mysqli = new mysqli($host, $username, $password, $dbName, $port);
第69行是:
# php -m | grep -i mysql
mysqli
mysqlnd
pdo_mysql
运行:
<?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();
?>
似乎表明我已经安装了相关的软件包。实际上,如果我尝试正常的PHP连接,它可以工作:
# 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>
输出:
{{1}}
有什么想法吗?
感谢。
答案 0 :(得分:0)
我遇到了同样的问题! mysqli上的导入有点问题。 我更改了
$this->mysqli = new mysqli($host, $username, $password, $dbName, $port);
从 ZC.php 到
$this->mysqli = new \mysqli($host,$username,$password, $dbName, $port);
工作了。