Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CONFIG.PHP
- <?php
- /***************************************************************************/
- /* Author: Nyle E. Davis Create Date: 12/10/05 */
- /* E-Mail: davisoftaec@gmail.com Revision: 1.0 */
- /* Purpose: This file contains the preset vars and definitions that */
- /* direct the calling and processing for the current process. */
- /* This file is written into by the parse_sql.php screen proc */
- /* to setup processing with the parse_sql_proc.php process so */
- /* the process can run from the command line via a cron job. */
- /***************************************************************************/
- /* Mod by: Nyle E. Davis Mod Date: 12/09/05 */
- /* Change: Added debug vars of: */
- /* DBUG_ME ==> Does array and var dumps, */
- /* INFO_ME ==> Allow run of phpinfo() statements, */
- /* PRUN_ME ==> Does other process run debugging. */
- /* SHOW_ME ==> Shows/echos all set vars, */
- /* STOP_ME ==> Stop processing with a die() statement. */
- /* Notes: The debug var PRUN_ME can be assigned values of 0-9 where 0 is */
- /* off and the other values can turn on upto 9 debugging tests. */
- /***************************************************************************/
- // Define the debugging Constants
- define ( 'DBUG_ME', 1 ); // 0=off, 1=on
- define ( 'INFO_ME', 0 ); // 0=off, 1=on
- define ( 'PRUN_ME', 0 ); // 0=off, 1-9=on by test type
- define ( 'SHOW_ME', 1 ); // 0=off, 1=on
- define ( 'STOP_ME', 0 ); // 0=off, 1=on end where set in code.
- $et_ray = array(); // Add the module names to test in this array
- // End debugging vars
- $crdir = getcwd().'/';
- // The values after this line will be written in by the parse_sql.php screen.
- // Set the DB constants
- define ( 'DB_HST', 'localhost' ); // DB Host
- define ( 'DB_PRT', 3306 ); // DB Port
- define ( 'DB_UID', 'ndavis' ); // DB User
- define ( 'DB_PWD', 'nomened1497' ); // DB Password
- define ( 'DB_DFD', '*.*' ); // DB Default DB
- define ( 'DB_DTB', true ); // DB Drop Tables enabled
- define ( 'DB_STR', false ); // DB Structure only enabled
- define ( 'DB_COM', true ); // DB Export Comments enabled
- define ( 'DB_SIZ', '12M' ); // DB Max File Size Setting
- // Set Backup Directory
- define ('BUP_DIR', '/backups/DB Backups/Dumps');
- // Set Other Constants
- define ('MAX_RWS', 10000);
- // end definitions
- ?>
- PARSE_SQL.PHP
- <?php
- /***************************************************************************/
- /* Author: Nyle E. Davis Create Date: 12/10/05 */
- /* E-Mail: davisoftaec@gmail.com Revision: 1.0 */
- /* Purpose: This file contains the preset vars and definitions that */
- /* direct the calling and processing for the current process. */
- /***************************************************************************/
- /* Mod by: Nyle E. Davis Mod Date: 12/09/05 */
- /* Notes: The debug var PRUN_ME can be assigned values of 0-9 where 0 is */
- /* off and the other values can turn on upto 9 debugging tests. */
- /***************************************************************************/
- // Parse .sql
- define ('SHOW_ME', 0);
- if (SHOW_ME==2) {
- foreach ($_POST as $key => $val) {
- echo "PK=> $key PV=> $val <br>";
- } // end foreach $_POST
- foreach ($_GET as $key => $val) {
- echo "GK=> $key GV=> $val <br>";
- } // end foreach $_POST
- } // end if SHOW_ME
- if (isset($_POST['pfile'])) {
- // $ffname = __FILE__;
- $ffname = $_POST['pfile'];
- $nfile = __FILE__;
- $fname = realpath($ffname);
- $rlpath = truepath($ffname);
- $realpt = realpath($ffname);
- echo "FN=> $ffname FNM=> $fname NF=> $nfile <br>";
- echo "R=> $rlpath RP=> $realpt <br>";
- var_dump($_FILES);
- // filePathParts($info);
- } // end if isset $_POST
- foreach ($_FILES as $name => $file) {
- echo "TN=> $name FN=> $file <br>";
- }
- //phpinfo();
- function read_fas_array ($myfile) {
- echo "Found Array Loading! <br>";
- $ret_ray = array();
- $f_hand = fopen($myfile, "r");
- while (!feof($file_handle)) {
- $ret_ray[] = fgets($file_handle);
- }
- fclose($file_handle);
- return $ret_ray;
- } // end function
- function parse_to_files ($myray) {
- echo "Found Parse Processing! <br>";
- } // end function
- function filePathParts($arg1) {
- echo "Dir=>".$arg1['dirname']."<br>";
- echo "Bas=>".$arg1['basename']."<br>";
- echo "Ext=>".$arg1['extension']."<br>";
- echo "Fnm=>".$arg1['filename']."<br>";
- }
- function truepath($path){
- // whether $path is unix or not
- $unipath=strlen($path)==0 || $path{0}!='/';
- // attempts to detect if path is relative in which case, add cwd
- if(strpos($path,':')===false && $unipath)
- $path=getcwd().DIRECTORY_SEPARATOR.$path;
- // resolve path parts (single dot, double dot and double delimiters)
- $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
- $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
- $absolutes = array();
- foreach ($parts as $part) {
- if ('.' == $part) continue;
- if ('..' == $part) {
- array_pop($absolutes);
- } else {
- $absolutes[] = $part;
- }
- }
- $path=implode(DIRECTORY_SEPARATOR, $absolutes);
- // resolve any symlinks
- if(file_exists($path) && linkinfo($path)>0)$path=readlink($path);
- // put initial separator that could have been lost
- $path=!$unipath ? '/'.$path : $path;
- return $path;
- }
- ?>
- <html>
- <head>
- <title>SQL File Parsing</title>
- </head>
- <body bgcolor='#ffbdaa'>
- <!-- FORM NAME='sqlp' METHOD='POST' enctype="multipart/form-data" -->
- <FORM NAME='sqlp' METHOD='POST' ACTION="<?php echo $_SERVER['PHP_SELF']; ?>">
- <table align='center' width='70%' border='0' cellspacing='0' cellpadding='0'>
- <tr>
- <td> </td>
- </tr>
- <tr>
- <td colspan=3 align='center'><h2>SQL File Parsing</h2></td>
- </tr>
- <tr>
- <td> </td>
- </tr>
- <tr>
- <td width='38%' align='right'>File to Parse:</h2></td>
- <td> </td>
- <td width='58%' align='left'>
- <input type='file' id='pfile' name='pfile' value='Browse'>
- </td>
- </tr>
- <tr>
- <td> </td>
- </tr>
- <tr>
- <td colspan=3 width='45%' align='center'>
- <input type='submit' value='Parse File'>
- </td>
- </tr>
- <tr>
- <td> </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- PARSE_SQL_CLASS.PHP
- <?php
- /***************************************************************************/
- /* Author: Nyle E. Davis Create Date: 12/10/05 */
- /* E-Mail: davisoftaec@gmail.com Revision: 1.0 */
- /* Purpose: This file contains the preset vars and definitions that */
- /* direct the calling and processing for the current process. */
- /***************************************************************************/
- /* Mod by: Nyle E. Davis Mod Date: 12/09/05 */
- /* Change: Added debug vars of: */
- /* DBUG_ME ==> Does array and var dumps, */
- /* INFO_ME ==> Allow run of phpinfo() statements, */
- /* PRUN_ME ==> Does other process run debugging. */
- /* SHOW_ME ==> Shows/echos all set vars, */
- /* STOP_ME ==> Stop processing with a die() statement. */
- /* Notes: The debug var PRUN_ME can be assigned values of 0-9 where 0 is */
- /* off and the other values can turn on upto 9 debugging tests. */
- /***************************************************************************/
- define('MSB_VERSION', '1.0.0');
- define('MSB_NL', "\r\n");
- class BackupMySQL {
- var $server = 'localhost';
- var $port = 3306;
- var $username = 'root';
- var $password = '';
- var $database = '';
- var $link_id = -1;
- var $connected = false;
- var $tables = array();
- var $drop_tables = true;
- var $struct_only = false;
- var $comments = true;
- var $backup_dir = '/backups/DB Backups/Dumps';
- var $fname_format = 'Y_m_d';
- var $error = '';
- function Execute($file_name,$database,$table_name,$start,$end,$max_rows) {
- $this->_Connect();
- if (!($sql = $this->_Retrieve($database,$table_name,$start,$end,$max_rows)))return false;
- return $this->_SaveToFile($file_name, $sql);
- }
- function _Connect() {
- $value = false;
- if (!$this->connected) {
- $host = $this->server . ':' . $this->port;
- $this->link_id = mysql_connect($host, $this->username, $this->password);
- }
- if ($this->link_id) {
- if (empty($this->database)) {
- $value = true;
- } elseif ($this->link_id !== -1) {
- $value = mysql_select_db($this->database, $this->link_id);
- } else {
- $value = mysql_select_db($this->database);
- } // end if empty
- } // end if $this->link_id
- if (!$value) {
- $this->error = mysql_error();
- } // end if !value
- return $value;
- } // end function _Connect
- function _DisConnect() {
- $value = false;
- if ($this->connected) {
- $host = $this->server . ':' . $this->port;
- $this->link_id = mysql_connect($host, $this->username, $this->password);
- }
- } // end function _Connect
- function _Query($sql) {
- if ($this->link_id !== -1) {
- $result = mysql_query($sql, $this->link_id);
- } else {
- $result = mysql_query($sql);
- } // end if $this->link_id
- if (!$result) {
- $this->error = mysql_error();
- } // end if !result
- return $result;
- } // end function _Query
- function _GetDBSize($db_max) {
- $this->_Connect();
- $v_ray = array(); // Set output array
- $value = array(); // Set array for small DBs
- $large = array(); // Set array for large DBs
- $sqlvl = "SELECT `table_schema`, ".
- "sum( data_length + index_length ) / 1024 / 1024 ".
- "`db_size` FROM `information_schema`.`tables` ".
- "GROUP BY `table_schema`;"
- if (!($result = $this->_Query('$sqlvl'))) { return false; } // end if !result
- while ($row = mysql_fetch_row($result)) {
- if ($row['db_size']>$db_max) {
- $large[] = $row;
- } else {
- $value[] = $row;
- }
- } // end while $row
- $v_ray = array(0=>$value,1=>$large);
- return $v_ray;
- } // end function _GetDBSize
- function _GetTBLSize($db_max,$tbl_array) {
- $this->_Connect();
- $v_ray = array(); // Set output array
- $value = array(); // Set array for small DBs
- $large = array(); // Set array for large DBs
- $sqlvs = "SELECT `table_schema`, , `table_name`".
- "sum( data_length + index_length ) / 1024 / 1024 ".
- "`db_size` FROM `information_schema`.`tables` ";
- $sqlve = "GROUP BY `table_name` ORDER BY `table_schema` , `table_name`;";
- foreach ($tbl_array as $key => $val) {
- echo "K=> $key V=> $val <br>";
- }
- //return;
- if (!($result = $this->_Query('$sqlvl'))) { return false; } // end if !result
- while ($row = mysql_fetch_row($result)) {
- if ($row['db_size']>$db_max) {
- $large[] = $row;
- } else {
- $value[] = $row;
- }
- } // end while $row
- $v_ray = array(0=>$value,1=>$large);
- return $v_ray;
- } // end function _GetTBLSize
- // HERE HERE HERE HERE HERE HERE HERE
- function _ExportList($list_ray) {
- } // end function _GetTBLSize
- function _ImportList($list_ray) {
- } // end function _GetTBLSize
- function _ParseLarge($table) {
- } // end function _GetTBLSize
- function _GetTables($database) {
- $this->_Connect();
- $value = array();
- if (!($result = $this->_Query('SHOW TABLES'))) {
- return false;
- } // end if !(result
- while ($row = mysql_fetch_row($result)) {
- if (!($result1 = $this->_Query('SELECT count(*) FROM `'.$row[0].'`'))) {
- return false;
- }
- $row1 = mysql_fetch_row($result1);
- $value[] = $row[0].':'.$row1[0];
- } // end while $row
- if (!sizeof($value)) {
- $this->error = 'No tables found in database.';
- return false;
- } // end if !sizeof
- return $value;
- } // end function _GetTables
- function GetTables($database) {
- return $this->_GetTables($database);
- } // end function GetTables
- function _DumpTable($database,$table,$start,$end,$row_count) {
- $value = '';
- if ($start==0) {
- if ($this->comments) {
- $value .= '#' . MSB_NL;
- $value .= '# Table structure for table `'.$table. '`'. MSB_NL;
- $value .= '#' . MSB_NL . MSB_NL;
- } // end if $this->comments
- if ($this->drop_tables) {
- $value .= 'DROP TABLE IF EXISTS `'.$table. '`;'. MSB_NL;
- } // end if $this->drop_tables
- if (!($result = $this->_Query('SHOW CREATE TABLE `'.$table.'`'))) {
- return false;
- } // end if !$result
- $row = mysql_fetch_assoc($result);
- $value .= str_replace("\n", MSB_NL, $row['Create Table']) . ';';
- $value .= MSB_NL . MSB_NL;
- } // end if $start
- if (!$this->struct_only) {
- if ($start==0 && $this->comments) {
- $value .= '#' . MSB_NL;
- $value .= '# Dumping data for table `' . $table . '`' . MSB_NL;
- $value .= '#' . MSB_NL . MSB_NL;
- } // end if $start
- $value .= $this->_GetInserts($database,$table,$start,$end);
- } // end if !$this->struct_only
- if ($end>=$row_count) { $value .= MSB_NL . MSB_NL; }
- return $value;
- }
- function _GetInserts($database,$table,$start,$end)
- {
- $value = '';
- if (!($result = $this->_Query('SELECT * FROM `'.$table.'` LIMIT '.$start.','.$end)))
- {
- return false;
- }
- while ($row = mysql_fetch_row($result))
- {
- $values = '';
- foreach ($row as $data)
- {
- $values .= '\'' . addslashes($data) . '\', ';
- }
- $values = substr($values, 0, -2);
- $value .= 'INSERT INTO `'.$table . '` VALUES (' . $values . ');' . MSB_NL;
- }
- return $value;
- }
- function _Retrieve($database,$table_name,$start,$end,$row_count)
- {
- $value = '';
- if (!$this->_Connect())
- {
- return false;
- }
- if ($start==0 && $this->comments)
- {
- $value .= '#' . MSB_NL;
- $value .= '# MySQL database dump' . MSB_NL;
- $value .= '# Created by Database Backup class, ver. ' . MSB_VERSION . MSB_NL;
- $value .= '#' . MSB_NL;
- $value .= '# Host: ' . $this->server . MSB_NL;
- $value .= '# Generated: ' . date('M j, Y') . ' at ' . date('H:i') . MSB_NL;
- $value .= '# MySQL version: ' . mysql_get_server_info() . MSB_NL;
- $value .= '# PHP version: ' . phpversion() . MSB_NL;
- if (!empty($this->database))
- {
- $value .= '#' . MSB_NL;
- $value .= '# Database: `' . $this->database . '`' . MSB_NL;
- }
- $value .= '#' . MSB_NL . MSB_NL . MSB_NL;
- }
- if (!($table_dump = $this->_DumpTable($database,$table_name,$start,$end,$row_count)))
- {
- $this->error = mysql_error();
- return false;
- }
- $value .= $table_dump;
- return $value;
- }
- function _SaveToFile($fname, $sql)
- {
- if (!($f = fopen($fname, 'a')))
- {
- $this->error = 'Can\'t create the output file.';
- return false;
- }
- fwrite($f, $sql);
- fclose($f);
- return true;
- } // end function _SaveToFile
- } // end class
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement