【发布时间】:2015-10-26 02:46:38
【问题描述】:
我正在尝试为我的应用程序使用 FullCalendars 惊人的 jquery 日历插件,但我无法从 SQL Server 在我的日历中生成事件。
这是我的代码: 第一个JS
$(document).ready(function() {
var date = new Date();
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
droppable: true,
eventLimit: true,
eventsources: 'events.php'
});
});
第二个 events.php 文件
<?php
$serverName = "ADMIN-PC\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"testing", "UID"=>"sa", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
} else {
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$sql = "SELECT id, custcode, title, description, datetime, status
FROM dbo.calls";
$stmt=sqlsrv_query($conn, $sql);
// Initializes a container array for all of the calendar events
$jsonArray = array();
while($row = sqlsrv_fetch_array($stmt))) {
$custcode = $row['custcode'];
$date = $row['datetime'];
// Stores each database record to an array
$buildjson = array('title' => "$custcode", 'start' => "$date", 'allday' => false);
// Adds each array into the container array
array_push($jsonArray, $buildjson);
}
// Output the json formatted data so that the jQuery call can read it
echo json_encode($jsonArray);
?>
目前我没有收到任何事件或错误!救命!!!
谢谢大家:)
【问题讨论】:
-
events.php 的输出是什么?
-
@Bulat 目前什么都没有,它被我的 js 调用,然后输出到 html 页面上的 div 中。..
-
直接点击页面的输出是什么?
-
@bulat "可捕获的致命错误:无法将类 DateTime 的对象转换为第 27 行 C:\wamp\www\support\assets\js\pages\events.php 中的字符串"跨度>
-
第 27 行 // 将每个数据库记录存储到一个数组 $buildjson = array('title' => "$custcode", 'start' => "$date", 'allday' => false );
标签: php jquery sql sql-server fullcalendar