<?php /* * Class Object examples and documentation * Example table: * CREATE TABLE `db`.`users` ( `CREATE TABLE IF NOT EXISTS `users` ( `id` int(5) NOT NULL AUTO_INCREMENT, `username` varchar(8) NOT NULL, `name` varchar(64) NOT NULL, `lastname` varchar(64) NOT NULL, `password` varchar(8) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
-- -- Dumping data for table `users` --
INSERT INTO `users` (`id`, `username`, `name`, `lastname`, `password`) VALUES (1, 'administ', 'Ralph', 'Lauren', 'clothes'), (2, 'jjhonsto', 'Joe', 'Jhonston', 'incredib');
); * */
//MUST be connected $link = mysql_connect('localhost', 'root', 'pass'); if (!$link) { die('Not connected : ' . mysql_error()); }
// make foo the current db $db_selected = mysql_select_db('development', $link); if (!$db_selected) { die ('Can\'t use development : ' . mysql_error()); } include_once("Class.Object.php");
if(isset($_GET['rename'])) { //Lets work with users $user = new Object("users", "1"); $user->name = "Casper"; //You can access the properties now echo "Now, User number ".$user->id." is named ".$user->name."<br />"; echo " <a href=\"test.php?reload\">Reload</a>"; } else { if(!isset($_GET['reload'])) { //Lets work with users $user = new Object("users", "1"); //You can access the properties now echo "User number ".$user->id." is named ".$user->name."<br />"; echo "Now, his name will be Rudolph, but you won't see it untill you reload the page!<br />"; $user->name = "Rudolph"; echo " <a href=\"test.php?reload\">Reload</a>"; } else { //Lets work with users $user = new Object("users", "1"); //You can access the properties now echo "New name for id ".$user->id." is ".$user->name."<br />"; echo " <a href=\"test.php?rename\">Rename him to Casper</a>"; mysql_close(); } } // ?>
|