我是PHP的新手,我想在内部网络上使用amcharts的免费图表。这些图表将连接到ODBC数据库。 我找到了一个解释how to connect to "mysql"的教程。 但我不知道如何修改该代码,因此它将连接到我已经存在的ODBC数据库。
我编写了以下代码似乎正在运行,但我只是收到一条“正在加载数据...”的消息,而不是其他内容:
DATA.PHP文件:
<?php
// we need this so that PHP does not complain about deprecated functions
error_reporting( 0 );
// Connect to SQL
$link = odbc_connect("Driver={SQL Server Native Client 10.0};Server=XXXXXXXX;Database=XXXXXX;Trusted_Connection=Yes", "", "");
if ( !$link ) {
die( 'Could not connect: ' . odbc_error() );
}
// Fetch the data
$query = "
select distinct last_date,
count(last_date) as NumberOfBIS
from [dbo].[xxxxxx]
group by last_date
order by last_date";
$result = odbc_exec($link, $query);
// All good?
if ( !$result ) {
// Nope
$message = 'Invalid query: ' . odbc_error() . "\n";
$message .= 'Whole query: ' . $query;
die( $message );
}
// Print out rows
$data = array();
while ( $row = odbc_fetch_array($result) ) {
$data[] = $row;
}
echo json_encode( $data );
// Close the connection
odbc_close( $link );
?>
HTML文件:
`<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>amCharts tutorial: Loading external data</title>
<script src="amcharts/amcharts.js"></script>
<script src="amcharts/serial.js"></script>
<script src="amcharts/plugins/dataloader/dataloader.min.js"></script>
</head>
<body>
<div id="chartdiv" style="width: 100%; height: 500px;"></div>
<script>
var chart = AmCharts.makeChart( "chartdiv", {
"type": "serial",
"dataLoader": {
"url": "data.php"
},
"pathToImages": "http://www.amcharts.com/lib/images/",
"categoryField": "category",
"dataDateFormat": "YYYY-MM-DD",
"startDuration": 1,
"categoryAxis": {
"parseDates": true
},
"graphs": [ {
"valueField": "value1",
"bullet": "round",
"bulletBorderColor": "#FFFFFF",
"bulletBorderThickness": 2,
"lineThickness ": 2,
"lineAlpha": 0.5
}, {
"valueField": "value2",
"bullet": "round",
"bulletBorderColor": "#FFFFFF",
"bulletBorderThickness": 2,
"lineThickness ": 2,
"lineAlpha": 0.5
} ]
} );
</script>
</body>
</html>`