Location: PHPKode > scripts > Table Data Management > table-data-management/example1.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 (hide@address.com)
* @uses		TableDataManagement, MySQLConnection, TableColumn

/** BEGIN: Include the necessary files **/
/** 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") {	
	//Load the POST array into the content object (needed for the save action)
	//check to see if we must save or update (if contentId = 0, it means we have a new content page)
	if($contentId > 0) {
		trigger_error("Your changes have been updated.", MESSAGE);		
	} else {
		//When saving, we store also the original creationdate 
		$objContent->set("creationdate", date("Y-m-d H-i-s"));
		trigger_error("The new content has been stored.", MESSAGE);

} else if($frmEvent == "delete") {
	trigger_error("The content has been removed", MESSAGE);
} else {
	//Load the specified content

//Retrieve the loaded content from the database
$theContent = $objContent->get("content");

echo $theContent;
Return current item: Table Data Management