PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of SPAM   pork.dbObject   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: demo page + sample code
Class: pork.dbObject
Map objects into MySQL database table rows
Author: By
Last change:
Date: 17 years ago
Size: 1,688 bytes


Class file image Download

// Welcome to the Pork.Iframe ultrasimple testpageŽ
// Step one: import ./sample_database.sql into mysql.
// Step two: go to ./settings/dbsettings.php and adjust your connection info
// Step three: Run this file in your local php webserver :-)

// For more info: see

include('./includes/functions.php'); // this just defines the __autoload();

global $db; // make sure it's called db and global. Pork.dbObject uses it.

$db = new dbConnection('./settings/dbsettings.php'); // you probably want to move this somewhere out of your WWWroot.

$weblog = new Blog(); // create an empty object to work with.
$weblog->Author = 'SchizoDuckie'; // mapped internally to strAuthor.
$weblog->Title = 'A test weblog';
$weblog->Story = 'This is a test weblog!';
$weblog->Posted = date("Y-m-d H:i:s");
$weblog->Save(); // Checks for any changed values and inserts or updates into DB.

$tag1 = new Tag(); // create a new tag to add to this weblog
$tag1->Tag = 'TestTag';

$reply = new Reaction(); // and a reply.
$reply->Poster = 'Some guy';
$reply->ReplyDate = date("Y-m-d");
$reply->Reaction = "woo hah!";

"Just inserted a new weblog with id: {$weblog->ID}, and added a tag and a reply<br>";
// now fetch the last 10 posts by SchizoDuckie, order by posted desc.
$weblogs = $weblog->Find("Blog", array("Author"=>"SchizoDuckie"), array("order by Posted desc", "limit 0,10"));

$weblogs != false)
    foreach (
$weblogs as $blog)

"These queries where executed:<pre>");