Here we discuss how to bind the gantt to a database table in PHP and then discuss how to persist changes made by the end user into the database in the 2 child topics.
Establishing Connection
We cover the following 2 database types.
- MYSQL Database
- SQLite database(.db) file
a) MYSQL connection is established using PHP PDO statement using 'DatabaseUtilities' (which is inside ../PHPWrappers\RadiantQ.Web.PHP.JQGantt\lib) which can be called as follows,
|
// Establishes connection for MYSQL. $db = new DatabaseUtilities('mysql:host=localhost;dbname=taskdb','tasks',$properties,'root','password'); |
Above, the 'mysql host and database name' is given as the first argument, table name is the second argument, the 'root' and 'password' are the third and fourth arguments respectively.
b) For establishing a connection to an SQLite database(.db) file, the arguments of DatabaseUtilities are as follows,
|
// Establishes connection for SQLite Database file. //Username and password are not necessary for sqlite db file. Hence null values are passed as arguments. $db = new DatabaseUtilities('sqlite:../../Tasks.db','tasks',$properties,null,null); |
In this the first argument is the 'path to the database file'. The second is the 'tablename'.
Note : The following implementation for enabling CRUD operations are common for both MYSQL and SQLite.
To Fetch data from Database
To read data from database you have to call the "fetchTask" function as below,
|
// To read data from database. $result = $db->fetchTask(); |
The fetchTask() performs the following operation to read data from database.
|
public function fetchTask() { // Create SQL select statement $statement =$db->prepare("SELECT * FROM tasks"); // Execute the statement $statement->execute(); // The result of 'read' operation is all tasks from the tasks table. $result = $statement->fetchAll(PDO::FETCH_CLASS); return $result; } |
� RadiantQ 2022. All Rights Reserved.