Category Archives: data

Create Zip Archive of Folder and All Contents

PHP code snippet to Create Zip Archive of Folder and All Contents – without the full directory path being included.

<?php

//function to zip an entire folder to back a backup
//saves to archive/year/month/day/filename.zip
function createZip($zipName,$folderToZip)
{
      // get year digits
      $year = date("Y");
      //create year directory if doesn't exist
      if (!is_dir('archive/'.$year))
      {
          mkdir('archive/'.$year);
      }

      //get month digits
      $month = date("m");
      //create month directory if doesn't exist
      if (!is_dir('archive/'.$year.'/'.$month))
      {
          mkdir('archive/'.$year.'/'.$month);
      }

      //get day digits
      $day = date("d");
      //create day directory if doesn't exist
      if (!is_dir('archive/'.$year.'/'.$month.'/'.$day))
      {
          mkdir('archive/'.$year.'/'.$month.'/'.$day);
      }

      $zipFile = 'archive/'.$year.'/'.$month.'/'.$day.'/'.$zipName.'.zip';

      ini_set("max_execution_time", 300);
      // create object
      $zip = new ZipArchive();
      // open archive
      if ($zip->open($zipFile, ZIPARCHIVE::CREATE) !== TRUE)
      {
            die ("Could not open archive");
      }
      // initialize an iterator
      // pass it the directory to be processed
      $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folderToZip."/"));
      // iterate over the directory
      // add each file found to the archive
      foreach ($iterator as $key=>$value)
      {
            $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
      }
      // close and save archive
      $zip->close();
      echo "Archive created successfully.";

      return $zipFile;
}
?>

Table Structure for Table `prof_twitter_data`

Shown below is a simple code for table structure of table

`prof_twitter_data`
--
-- Table structure for table `prof_twitter_data`
--

CREATE TABLE IF NOT EXISTS `prof_twitter_data` (
  `profTwitterId` bigint(11) NOT NULL AUTO_INCREMENT,
  `uid` bigint(11) NOT NULL,
  `name` varchar(52) NOT NULL,
  `screen_name` varchar(52) NOT NULL,
  `description` varchar(255) NOT NULL,
  `profile_image_url` varchar(255) NOT NULL,
  `url` varchar(255) NOT NULL,
  `location` varchar(52) NOT NULL,
  `friends_count` int(5) NOT NULL,
  `followers_count` int(5) NOT NULL,
  `status_id_str` varchar(52) NOT NULL,
  `status_text` varchar(255) NOT NULL,
  `status_created_at` varchar(52) NOT NULL,
  PRIMARY KEY (`profTwitterId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

All PHP Scripts on this website are provided by phpscripts4u.com where you can find all the latest PHP code snippets, plugins and libraries.

How to Use PHP Building Data Objects for Website?

Before going through the miraculous way on how to build data objects using PHP. Let us know what exactly the PHP Data Objects mean:

Well! PHP data object is referred to as the Database Connection Abstraction Library used for PHP 5 extension. It is the lightweight data access abstraction library connection (DBMS) which runs constantly for the assessment of the various data files on PHP script. It is the best application that is used for the reliable operation of the database system via PHP. The flexible working of the PHP building data objects make you to overcome the haphazard manner of rewriting the line code for every database.  With the PHP building data objects you need to write line code at once and use it anytime anywhere without any contradiction. It works with a great speed because it is written in the complied language using the PHP library functions such PEARDB OR ADOdb that use the expression of interpreting the requisite data in the most systematic and organized way. The use of the PHP building data objects makes you web administrator cell free from any other installation of scrupulous software for the running of the database of website with great proficiency. However, to use this requisite option you need to have the portable application supporting the functioning of various database system. Besides this, you require an ample amount of speed for the functioning of the PHP building data objects on specified database.

 

To run the PHP building data objects on the specific database operations you require a database- specific PDO driver that may help in easy and straightforward assessment of the database server. This particular server enhances the devised feature of the database as the regular extension features to carry out the regular task of the website.

 

The PHP building data objects come with the data-access abstraction layer that helps in generating the relative amount of response or queries for all the databases along with generic assessment. But it doesn’t offer feature related to database abstraction, so you won’t be facilitated with the rewriting of the MySQL or get a followance towards the missing characteristics of the web.

 

The PHP building data objects are usually found in the form of PECL extension and can be used only with PHP 5.0 application. Because the PDO can only be assessed using the OO features of the PHP 5. The installation of the requisite application for the database helps you in completing the daily db task in more refined way. It offers you the viable interaction with the db such as coding listing, updating, deleting or adding records and a lot more.

 

The PHP 5 extension application comes with the PHP’s stdClass feature that helps you to create an effective object for the requisite database of the website. For example, if you want to create a new object related to the storage of the data for the book, then you need to undergo the following steps:

 

1 $book = new stdClass;
2 $book->title = “ The Journey of the Noble Gnarble “;

 

3 $book->author = “Daniel Errico”
4 $book->publisher = ” Levine Books”;

 

5 $book->amazon_link = “http://www.amazon.com/xyz /“;