【问题标题】:Full Calendar Integration with SQL Server与 SQL Server 的完整日历集成
【发布时间】: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


【解决方案1】:

看来您需要在这里明确地将日期转换为字符串:

'start' => "$date"

像这样:

'start' => $date->format('Y-m-d H:i:s');

【讨论】:

  • 好的,我会看看..你知道如何将日期时间字段从 sql 转换为所需的格式,这也可以工作吗?道歉。
  • 即使是字符串,用引号包裹变量也是不好的做法
  • 我已经添加了您建议的代码行,但似乎我仍然在第 27 行收到该错误?
  • $buildjson = array('title' => "$custcode", 'start' => $date->format('Ymd H:i:s'), 'allday' => false );
  • 刚刚在上面添加 :) 感谢您在此方面的帮助!
猜你喜欢
  • 2012-06-27
  • 1970-01-01
  • 2022-01-24
  • 2020-03-28
  • 1970-01-01
  • 1970-01-01
  • 2017-06-30
  • 2012-08-17
  • 2013-08-14
相关资源
最近更新 更多