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 : SQL Parsing Class - parse text files with a list of MySQL query statements to be executed.
Categories : PHP, PHP Classes, Databases, MySQL Click here to Update Your Picture
MA Razzaque Rupom
Date : May 20th 2006
Grade : 5 of 5 (graded 3 times)
Viewed : 10516
File : 4403.php
Images : No Images for this code example.
Search : More code by MA Razzaque Rupom
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This is a simple class that can parse text files with a list of MySQL query statements to be executed.

The class splits the file lines, skips comment lines and gathers all consecutive lines until the one ends with semi-colon to get the complete SQL statement.

Each statement is executed as MySQL query to the current default MySQL database connection.

<?php
/**
* @author  :  MA Razzaque Rupom <rupom_315@yahoo.com>, <rupom.bd@gmail.com>
*             Moderator, phpResource (http://groups.yahoo.com/group/phpresource/)
*             URL: http://www.rupom.info 
* @version :  1.0* Version : 1.0
* Date     :  20 May, 2006
* Purpose  : Importing valid SQL dump to DB
* Release  : Released under GNU Public License
*/

class ParseSql
{
   var
$file;
   
   function
ParseSql($file)
   {     
     
$this->setFile($file);
       
$this->startParsing();
   }
   
   
/**
   * @purpose : Sets filename to be parsed
   * @params $file
   * @return none
   */
   
function setFile($file)
   {
     
$this->file = $file;
   }

   
/**
   * @purpose : Gets filename to be parsed
   * @params none
   * @return filename
   */
   
   
function getFile()
   {
      return
$this->file;
   }
   
   
/**
   * @purpose : Parses SQL file
   * @params none
   * @return none
   */

   
function startParsing()
   {

     
$file = $this->getFile();     
       
// Getting the SQL file content       
       
$content = file_get_contents($file);
               
       
// Processing the SQL file content             
       
$file_content = explode("\n",$content);           
     
     
       
$query = "";
       
         
// Parsing the SQL file content             
         
foreach($file_content as $sql_line)
          {       
             if(
trim($sql_line) != "" && strpos($sql_line, "--") === false)
             {             
               
$query .= $sql_line;
                 
// Checking whether the line is a valid statement
                 
if(preg_match("/(.*);/", $sql_line))
                  {
                     
$query = substr($query, 0, strlen($query)-1);                       
                       
//Executing the parsed string, returns the error code in failure
                       
$result = mysql_query($query)or die(mysql_error());
                       
$query = "";
                  }
             }
          }
//End of foreach
       
       
return true;
   }
//End of function
   
} //End of class


//Usage of the class

mysql_connect("hostname","username","password") or die('Cant Connect...');
mysql_select_db("yourdb") or die('DB Connection Problem...');;


$parseObj = new ParseSql('your_sql_file.sql');
$res      = $parseObj->startParsing();

if(
$res)
{
   echo
"<b>Query Executed Successfully.</b>";
}

?>



[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
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 Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL