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

php – Fullcalendar + connect to SQL + PHPMaker

Posted by: admin February 25, 2020 Leave a comment

Questions:

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

<?php
$serverName = "94.46.22.1\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);
?>

CUSTOM FILE FOR CALENDAR – calendar.php

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

<script src='fullcalendar/core/main.js'></script>
<script src='fullcalendar/interaction/main.js'></script>
<script>
...
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'interaction' ],
...
});
...
</script>
<script>
    $(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: 'eventlist.php'
    });
 });
    </script>
</head>
<body>

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

</body>

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

How to&Answers: