<?php
/**
* Example of how to use the tabledatamanagement object on a specific table.
* The table we use is a table named content, with columns: id (int), content (text), creationdate (date).
*
* This script shows you how you can use the tabledatamanagement object to handle your actions to your tables.
* You could also extend the tabledatamanagement object, so that certain methods are extended or disabled (by placing
* an empty method (for f.e. delete)).
*
* This example show how:
* - posted data can be used to store the data into the table
* What's cool (IMHO), is that you can paste the whole POST array to the object and the object it self
* nows which data to extract from it and also how it must be stored into the database (also using the necessary
* escapes)
* - a specific content page can be deleted
* - a specific content page can be loaded
* The object it self knows which column to use for a load (since the tablekey is "calculated" during initialization)
*
* @author S.Radovanovic (saskovic@hotmail.com)
* @uses TableDataManagement, MySQLConnection, TableColumn
*/
/** BEGIN: Include the necessary files **/
include("MySQLConnection.class.php");
include("TableColumn.class.php");
include("TableDataManagement.class.php");
/** END: Include the necessary files **/
/** BEGIN: Initialize objects **/
//Create a connection to the database (fill in the yours)
$objMySQLConnection = new MySQLConnection("yourdatabase", "yourusername", "yourpassword", "yourdbhost");
//Initialize our content object (specifying that we use the content table)
$objContent = new TableDataManagement($objMySQLConnection, "content");
/** END: Initialize objects **/
//See if a contentId was specified
$contentId = $_POST["contentId"];
//Set the contentId into the content object (for usage in save, update, delete and load)
$objContent->set("id", $contentId);
//Check to see which frmEvent was called
if($frmEvent == "save") {
//SAVE/UPDATE
//Load the POST array into the content object (needed for the save action)
$objContent->setArray($_POST);
//check to see if we must save or update (if contentId = 0, it means we have a new content page)
if($contentId > 0) {
//UPDATE
$objContent->update();
trigger_error("Your changes have been updated.", MESSAGE);
} else {
//SAVE
//When saving, we store also the original creationdate
$objContent->set("creationdate", date("Y-m-d H-i-s"));
$objContent->save();
trigger_error("The new content has been stored.", MESSAGE);
}
} else if($frmEvent == "delete") {
//DELETE
$objContent->delete();
trigger_error("The content has been removed", MESSAGE);
} else {
//LOAD
//Load the specified content
$objContent->load();
}
//Retrieve the loaded content from the database
$theContent = $objContent->get("content");
echo $theContent;
?>
|