WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Create a local copy of the TemplateMonster DB
Categories : PHP, Databases, MySQL
Boaz Yahav
Date : Mar 25th 2005
Grade : 2 of 5 (graded 3 times)
Viewed : 14260
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Boaz Yahav
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

#!/usr/local/bin/php -q
<?
//This script is set to run as a CGI ver of PHP. Remove the 1st line
//if you want to run it from the web.
//
//The script connects to the templatemonster Webapi, downloads all
//of the data and builds a local database with the data. This comes
//handy if you want to build your own affiliate site and wand to use
//your own database.
//
//You should run this script on a daily basis to make sure that your
//data is accurate.

//Your DB connection
include"dbcon.inc";

//Change the name to your DB
mysql_select_db("Templates");

//Create Categories
function GetURL($domain,$uri) {
   
   
$fp=fsockopen("$domain",80, &$errno, &$errstr,10);   
    if (
$fp) {
       
socket_set_blocking($fp,false);
       
fwrite($fp,"GET $uri HTTP/1.0\r\n");
       
fwrite($fp,"host:$domain\r\n");
       
fwrite($fp,"User-Agent:WeberDev.com\r\n\r\n");
       
$message="";
        while(!
feof($fp)){
           
$message .= fgets($fp,4096);
        }
       
       
$CategoryArray=explode("\r\n",$message);
        For(
$i=1 ; $i <=8 ; $i++) {
           
array_shift($CategoryArray);
        }
        return
$CategoryArray;
    }
}

function
GetCategories() {
   
mysql_query("DROP TABLE IF EXISTS Categories") or die(mysql_error());
   
mysql_query("    CREATE TABLE Categories (
                    CategoryID int(11) NOT NULL auto_increment,
                    TCategoryID int(11) NOT NULL default '0',
                    CategoryName varchar(50) NOT NULL default '',
                    PRIMARY KEY  (CategoryID),
                    KEY TCategoryID (TCategoryID),
                    KEY CategoryName (CategoryName)
                    ) TYPE=MyISAM
    "
) or die(mysql_error());
   
$CategoryArray=GetURL("www.templatemonster.com","/webapi/categories.php?delim=;");
   
    For(
$i = 0 ; $i < count($CategoryArray) ; $i++) {
       
$String=explode(";",$CategoryArray[$i]);
       
$String[0]=trim($String[0]);
       
$String[1]=trim($String[1]);
        If(
$String[0] != "") {
           
mysql_query("INSERT INTO Categories
                            (TCategoryID,CategoryName)
                        VALUES
                            (
$String[0],'$String[1]')   
            "
) or die(mysql_error());
        }   
    }
   
//Optional, to remove the Adult category, remove the remark from the next line.
    //mysql_query("DELETE FROM Categories WHERE trim(CategoryName) = 'Adult'") or die(mysql_error());
}


//Create Templates
function GetTemplates() {
   
mysql_query("DROP TABLE IF EXISTS Templates") or die(mysql_error());
   
mysql_query("CREATE TABLE Templates (
                  TemplateID int(11) NOT NULL auto_increment,
                  TTemplateID int(11) NOT NULL default '0',
                  price int(11) NOT NULL default '0',
                  exclusive_price int(11) NOT NULL default '0',
                  date_of_adding date NOT NULL default '0000-00-00',
                  number_of_downloads int(11) NOT NULL default '0',
                  is_hosting tinyint(4) NOT NULL default '0',
                  is_flash tinyint(4) NOT NULL default '0',
                  is_adult tinyint(4) NOT NULL default '0',
                  is_unique_logo tinyint(4) NOT NULL default '0',
                  is_non_unique_logo tinyint(4) NOT NULL default '0',
                  is_unique_corporate tinyint(4) NOT NULL default '0',
                  is_non_unique_corporate tinyint(4) NOT NULL default '0',
                  TAuthorID int(11) NOT NULL default '0',
                  is_full_site_template tinyint(4) NOT NULL default '0',
                  number_of_pages int(11) NOT NULL default '0',
                  Screenshots  varchar(255) NOT NULL default '',
                  PRIMARY KEY  (TemplateID),
                  KEY TTemplateID (TTemplateID),
                  KEY TAuthorID (TAuthorID)
                ) TYPE=MyISAM
        "
) or die(mysql_error());
   
$TemplateArray=GetURL("www.templatemonster.com","/webapi/templates_screenshots4.php?delim=;&filter=0");
    For(
$i = 0 ; $i < count($TemplateArray) ; $i++) {
       
$String=explode(";",$TemplateArray[$i]);
       
$String[0]=trim($String[0]);
       
$String[1]=trim($String[1]);
       
$String[2]=trim($String[2]);
       
$String[3]=trim($String[3]);
       
$String[4]=trim($String[4]);
       
$String[5]=trim($String[5]);
       
$String[6]=trim($String[6]);
       
$String[7]=trim($String[7]);
       
$String[8]=trim($String[8]);
       
$String[9]=trim($String[9]);
       
$String[10]=trim($String[10]);
       
$String[11]=trim($String[11]);
       
$String[12]=trim($String[12]);
       
$String[13]=trim($String[13]);
       
$String[14]=trim($String[14]);
       
$String[15]=trim($String[15]);


        If(
$String[0] != "") {
       
mysql_query("INSERT INTO Templates
                        (    TTemplateID,
                            price,
                            exclusive_price,
                            date_of_adding,
                            number_of_downloads,
                            is_hosting,
                            is_flash,
                            is_adult,
                            is_unique_logo,
                            is_non_unique_logo,
                            is_unique_corporate,
                            is_non_unique_corporate,
                            TAuthorID,
                            is_full_site_template,
                            number_of_pages,
                            Screenshots
                            )
                    VALUES
                        (   
$String[0],
                           
$String[1],
                           
$String[2],
                            '
$String[3]',
                           
$String[4],
                           
$String[5],
                           
$String[6],
                           
$String[7],
                           
$String[8],
                           
$String[9],
                           
$String[10],
                           
$String[11],
                           
$String[12],
                           
$String[13],
                           
$String[14],
                            '
$String[15]'
                        )   
        "
) or die(mysql_error());
    }
    }
}


//Create TemplateCategories
function GetTemplateCategories() {
   
mysql_query("DROP TABLE IF EXISTS TemplateCategories") or die(mysql_error());
   
mysql_query("CREATE TABLE TemplateCategories (
                  TemplateCategoriesID int(11) NOT NULL auto_increment,
                  TTemplateID int(11) NOT NULL default '0',
                  TCategoryID int(11) NOT NULL default '0',
                  PRIMARY KEY  (TemplateCategoriesID),
                  KEY TTemplateID (TTemplateID),
                  KEY TCategoryID (TCategoryID)
                ) TYPE=MyISAM
        "
) or die(mysql_error());
   
$TemplateCategoryArray=GetURL("www.templatemonster.com","/webapi/template_categories.php?delim=;");
    For(
$i = 0 ; $i < count($TemplateCategoryArray) ; $i++) {
       
$String=explode(";",$TemplateCategoryArray[$i]);
       
$String[0]=trim($String[0]);
       
$String[1]=trim($String[1]);
        If(
$String[0] != "") {
           
mysql_query("INSERT INTO TemplateCategories
                            (TTemplateID,TCategoryID)
                        VALUES
                            (
$String[0],'$String[1]')   
            "
) or die(mysql_error());
        }
    }
}

//Create Sources
function GetSources() {
   
mysql_query("DROP TABLE IF EXISTS Sources") or die(mysql_error());
   
mysql_query("CREATE TABLE Sources (
                  SourcesID int(11) NOT NULL auto_increment,
                  TTemplateID int(11) NOT NULL default '0',
                  SourcesName varchar(255) NOT NULL default '',
                  PRIMARY KEY  (SourcesID),
                  KEY SourcesName (SourcesName),
                  KEY TTemplateID (TTemplateID)
                ) TYPE=MyISAM
        "
) or die(mysql_error());
   
$SourcesArray=GetURL("www.templatemonster.com","/webapi/template_sources.php?delim=;");
    For(
$i = 0 ; $i < count($SourcesArray) ; $i++) {
       
$String=explode(";",$SourcesArray[$i]);
       
$String[0]=trim($String[0]);
       
$String[1]=trim($String[1]);
       
$String[1]=addslashes($String[1]);
        If(
$String[0] != "") {
           
mysql_query("INSERT INTO Sources
                            (TTemplateID,SourcesName)
                        VALUES
                            (
$String[0],'$String[1]')   
            "
) or die(mysql_error());
        }
    }
}

//Create Authors
function GetAuthors() {
   
mysql_query("DROP TABLE IF EXISTS Authors") or die(mysql_error());
   
mysql_query("CREATE TABLE Authors (
              AuthorID int(11) NOT NULL auto_increment,
              TAuthorID int(11) NOT NULL default '0',
              AuthorName varchar(50) NOT NULL default '',
              PRIMARY KEY  (AuthorID),
              KEY TAuthorID (TAuthorID),
              KEY AuthorName (AuthorName)
            ) TYPE=MyISAM
        "
) or die(mysql_error());
   
$AuthorsArray=GetURL("www.templatemonster.com","/webapi/authors.php?delim=;");
    For(
$i = 0 ; $i < count($AuthorsArray) ; $i++) {
       
$String=explode(";",$AuthorsArray[$i]);
       
$String[0]=trim($String[0]);
       
$String[1]=trim($String[1]);
       
$String[1]=addslashes($String[1]);
        If(
$String[0] != "") {
           
mysql_query("INSERT INTO Authors
                            (TAuthorID,AuthorName)
                        VALUES
                            (
$String[0],'$String[1]')   
            "
) or die(mysql_error());
        }
    }
}

//Create Keywords
function GetKeywords() {
   
mysql_query("DROP TABLE IF EXISTS Keywords") or die(mysql_error());
   
mysql_query("CREATE TABLE Keywords (
              KeywordID int(11) NOT NULL auto_increment,
              TTemplateID int(11) NOT NULL default '0',
              Keywords varchar(255) NOT NULL default '',
              PRIMARY KEY  (KeywordID),
              KEY Keywords (Keywords)
            ) TYPE=MyISAM
        "
) or die(mysql_error());
   
$KeywordsArray=GetURL("www.templatemonster.com","/webapi/template_keywords.php?delim=;");
    For(
$i = 0 ; $i < count($KeywordsArray) ; $i++) {
       
$String=explode(";",$KeywordsArray[$i]);
       
$String[0]=trim($String[0]);
       
$String[1]=trim($String[1]);
       
$String[1]=addslashes($String[1]);
        If(
$String[0] != "") {
           
mysql_query("INSERT INTO Keywords
                            (TTemplateID,Keywords)
                        VALUES
                            (
$String[0],'$String[1]')   
            "
) or die(mysql_error());
        }
    }
}

//Create Featured
function GetFeatured() {
   
mysql_query("DROP TABLE IF EXISTS Featured") or die(mysql_error());
   
mysql_query("CREATE TABLE Featured (
                  FeaturedID int(11) NOT NULL auto_increment,
                  TFeaturedID int(11) NOT NULL default '0',
                  PRIMARY KEY  (FeaturedID),
                  KEY TFeaturedID (TFeaturedID)
                ) TYPE=MyISAM
        "
) or die(mysql_error());
   
$FeaturedArray=GetURL("www.templatemonster.com","/webapi/featured.php?delim=;");
   
$String=explode(";",$FeaturedArray[0]);
    For(
$i = 0 ; $i < count($String) ; $i++) {
       
$String[$i]=trim($String[$i]);
        If(
$String[0] != "") {
           
mysql_query("INSERT INTO Featured
                            (TFeaturedID)
                        VALUES
                            (
$String[$i])   
            "
) or die(mysql_error());
        }
    }
}

GetCategories();
GetTemplates();
GetTemplateCategories();
GetSources();
GetAuthors();
GetKeywords();
GetFeatured();
?>



bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Simple db results paging example
Categories : PHP, MySQL, Databases, Form Processing
A Complete table(ADD,EDIT,VIEW,DELETE) management System PHP,MYSQL, JAVASCRIPT
Categories : PHP, MySQL, Java Script, Databases
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
for each record, do this to the first record, and do that to any subsequent record
Categories : PHP, Databases, MySQL, Beginner Guides
DBXML- A Class to backup databases in XML Format using web interface
Categories : PHP, PHP Classes, Databases, MySQL, XML
Dynamically generated pop-ups (Select items)
Categories : PHP, HTML and PHP, MySQL, Databases
DB Connection Function with error handling and email failure notices
Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging
database,php,mysql,demo,example,php3,training,tutorial,codes,code
Categories : Databases, MySQL, PHP, PHP Options and Info
Displaying records of database in more than one page (paging)
Categories : Databases, MySQL, PHP
MySQL Class to ease Database connectivity
Categories : MySQL, PHP Classes, Databases, PHP
This is a very simple BBS that uses MySQL
Categories : MySQL, Databases, Complete Programs, PHP
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
Create and restore backup of MySQL databases
Categories : MySQL, Databases, PHP, PHP Classes, Complete Programs
 Olaf Lederer wrote :1298
Hi Yahav,
funny... currently I`m busy with a class wit the same kind of functionallity. What I try do is to create the script much more compact without this long string split code. Take a look on my site later.