Location: PHPKode > projects > Atom PhotoBlog > apbClasses/MySQLPhoto.class.php
<?php
   /*
   MySQLPhoto.class - Extension of MySQL.class of Atom PhotoBlogger
   Copyright (C) 2007 by Sascha Tayefeh

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   */


   /*!
   CLASS-HIERARCHY:

   MySQL.class <- MySQLPhoto.class <- AtomPhotoBlog.class

   PARAMETERS (alphabetically sorted):
      public $apbPrefix="apb_";		// The default prefix of all photoblog-tables.

   METHODS (alphabetically sorted):
      public function mysqlCreateTables()	// Initialize all tables
      public function mysqlDeleteTables()	// Delete all tables
      public function mysqlQuery($query)	// A redefinition of MySQL::mysqlQuery(). This one lacks of warnings to avoid user-confusion.

   */


   require_once './apbClasses/MySQL.class.php';


   class MySQLPhoto extends MySQL
   {
      public $apbPrefix="apb_";

      public function mysqlCreateTables()
      {
	 /* Legal Entry Example:
	 * insert into ".$this->apbPrefix."entries (`picLink`,`tnLink`,`year`,`date`,`time`) 
	 * VALUES ("http://www.somewhere.dd/ll.jpg","http://www.somewhere.dd/tn_ll.jpg",2004,"2006-12-12","15:12:22");
	 */

	 $query="CREATE TABLE ".$this->apbPrefix."entries (";
	 $query.="`id` INT unsigned not null auto_increment unique,";
	 $query.="`picLink` VARCHAR(255) unique NOT NULL, ";
	 $query.="`tnLink` VARCHAR(255) unique NOT NULL,";
	 $query.="`fileName` VARCHAR(255) NOT NULL,";
	 $query.="`year` YEAR NOT NULL,";
	 $query.="`date` DATE NOT NULL,";
	 $query.="`time` TIME NOT NULL,";
	 $query.="`phpTimeStamp` INT UNSIGNED NOT NULL,";
	 $query.="`timeStamp` TIMESTAMP ,";
	 $query.="`hits` INT UNSIGNED default 0 NOT NULL,";
	 $query.="`title` VARCHAR(255) default \"UNTITLED\" NOT NULL,";
	 $query.="`comment` TEXT,";
	 $query.="`IP` VARCHAR(20),";
	 $query.="PRIMARY KEY (`id`)";
	 $query.=");";
	 $this->mysqlQuery($query);

	 $query="CREATE TABLE ".$this->apbPrefix."tags (";
	 $query.="`id` INT unsigned not null auto_increment unique,";
	 $query.="`entryId` int unsigned not null,";
	 $query.="`tag` varchar(40) not null,";
	 $query.="`timeStamp` TIMESTAMP,";
	 $query.="PRIMARY KEY (`id`)";
	 $query.=");";
	 $this->mysqlQuery($query);

	 $query="CREATE TABLE ".$this->apbPrefix."comments (";
	 $query.="`id` INT unsigned not null auto_increment unique,";
	 $query.="`entryId` int unsigned not null,";
	 $query.="`homepage` varchar(255),";
	 $query.="`email` varchar(255),";
	 $query.="`comment` TEXT NOT NULL,";
	 $query.="`timeStamp` TIMESTAMP,";
	 $query.="`parent` smallint unsigned not null default 0,";
	 $query.="`approved` tinyint unsigned not null default 0,";
	 $query.="`name` VARCHAR(50) NOT NULL,";
	 $query.="`IP` VARCHAR(20),";
	 $query.="PRIMARY KEY (`id`)";
	 $query.=");";
	 $this->mysqlQuery($query);
	 return;
      }

      // Redefine mysqlQuery(), skip errorcheck and warnings
      public function mysqlQuery($query)
      {
	 $buffer = mysql_query($query,$this->mysqlPointer);
	 return $buffer;
      }


      public function mysqlDeleteTables()
      {
	 $query="drop table ".$this->apbPrefix."comments;"; $this->mysqlQuery($query);
	 $query="drop table ".$this->apbPrefix."tags;"; $this->mysqlQuery($query);
	 $query="drop table ".$this->apbPrefix."entries;"; $this->mysqlQuery($query);
	 return;
      }

   }
?>
Return current item: Atom PhotoBlog