Home » Php » php – Fullcalendar + connect to SQL + PHPMaker

php – Fullcalendar + connect to SQL + PHPMaker

Posted by: admin February 25, 2020 Leave a comment


I’ve added with success, the fullcalendar to my phpmaker project.
It stops working when I try to connect the calendar to a table in the database.
Before trying to connect, I could see the calendar. After, I have page header, sidebar (in common with the rest of the website), page title and nothing else.
I’ve started with the code from both fullcalendar and a post here.

I have:

TABLE – events
ID, title, starttime, endtime, allDay

PHP EVENTS LIST – eventlist.php

$serverName = "\MSSQLSERVER2017"; //serverName\instanceName
$connectionInfo = array( "Database"=>"takeoffpt_", "UID"=>"takeoffp", "PWD"=>"Rodinhas110815!");
$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, title, start, end 
          FROM dbo.events";

$stmt=sqlsrv_query($conn, $sql);

// Initializes a container array for all of the calendar events
$jsonArray = array();

while($row = sqlsrv_fetch_array($stmt))) {
    $title = $row['title'];
    $start = $row['start'];
    $end = $row['end'];

    // Stores each database record to an array
    $buildjson = array('title' => "$title", 'start' => $start->format('Y-m-d H:i:s'), 'end' => $end- 
>format('Y-m-d H:i:s'), '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);


<?php // include_once $RELATIVE_PATH . "header.php" ?>
<!DOCTYPE html>
<html lang="en">
    <meta charset='utf-8' />

<script src='fullcalendar/core/main.js'></script>
<script src='fullcalendar/interaction/main.js'></script>
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'interaction' ],
    $(document).ready(function() {

var date = new Date();
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();

    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    editable: true,
    droppable: true,
    eventLimit: true,
    eventsources: 'eventlist.php'

    <div id='calendar'></div>


Any thoughts? Even if it’s not to use within PHPMaker…?

How to&Answers: