rdbms.cls.php
上传用户:jiangbw
上传日期:2022-03-16
资源大小:49k
文件大小:18k
- <?
- /*======================================================================*
- || #################################################################### ||
- || # BUILD UNDER PHP SCRIPTNET 3.2.1 FRAMEWORK ||
- || # ---------------------------------------------------------------- # ||
- || # Code2Art Open Source Software. All Rights Reserved. ||
- || # This file should be redistributed in whole or significant part. # ||
- || # ------------------ SCRIPTNET IS FREE SOFTWARE ------------------ # ||
- || # http://www.code2art.com | http://www.code2art.com/scriptnet # ||
- || # Copyleft by Benediktus Ardian Hersanto, SE # ||
- || # Sorry if this framework is still unavailable for public # ||
- || # because I still searching on my own head. # ||
- || #################################################################### ||
- *======================================================================*/
- /*======================================================================*
- || #################################################################### ||
- || DBF to MySQL Bulk Converter 2.0 ||
- ||______________________________________________________________________||
- || This utility was developed on 2006, since this were used to be on ||
- || my own library. But I think I should share it to you, because I ||
- || need to save my work on Internet (I don't believe on my own HD drive)||
- || it always crash and had a terrible bad sectors. ||
- || Thanks to all person who download this utility, I hope you enjoy it. ||
- || ||
- || Regards, ||
- || Benediktus Ardian Hersanto,SE (ardie_b@yahoo.com) ||
- /*======================================================================*/
- // ---------------------------------------------------------------------//
- // Free to use for everyone who understand PHP
- // ---------------------------------------------------------------------//
- // Last Update : 25.08.2008
- // LAST CHANGES
- // createNavigator : group by data counting have been replaced by this->Count
- // createNavigator : You can add link to other pages with JavaScript Command (18.09.2006)
- // createNavigator : You can add link to other pages with string manipulation function ex : base64_encode (09.09.2006)
- // Module Dependency
- // = EnvSetup Class available on file init.php or config.php
- /*
- *@author B. Ardian Hersanto
- *@copyright GNU as long as you're friends of mine, just kidding
- *@package DBComponents
- */
- // DATABASE CORE OBJECT / ABSTRACT CLASS //
- class RDBMS {
- var $hostname;
- var $username;
- var $password;
- var $database;
- var $port;
- var $server_type;
- var $debug = false;
- var $simulate = false;
- var $error = false;
- var $FILE,$LINE,$connected;
- var $HScroll_Limit=10;
- var $SQL_LIMIT = '';
- var $return_as_array = false;
- var $admin;
- var $dba_password;
- //Library Properties
- var $about = "GNU PHP RDBMS Component for PHP";
- var $log_errors = true;
- var $log_file = "/logs/dbms.log";
- var $proc_log = "/logs/process.log";
- var $error_msg = '';
- var $error_priority;
- var $version = "4.2.06-dev.27.01";
- var $ErrorMarkup = '<p><hr size="0" noshade color="#FF0000"><b><font size="2" face="Verdana">DATABASE ERROR LIST :</font></b></p>';
-
- // Page Navigator Template Vars
- var $start_page = "#";
- var $previous_page = "#";
- var $next_page = "#";
- var $end_of_page = "#";
- var $navigator = "<span class="page_nav_inactive"> 1 </span>";
- var $nav_template = '<span> <a class="navigator_text" href="$this->start_page">Home</a></span> |<span> <a class="navigator_text" href="$this->previous_page">Previous</a> </span>|$this->navigator|<span> <a class="navigator_text" href="$this->next_page">Next</a></span> |<span> <a class="navigator_text" href="$this->end_of_page">Last</a></span>';
- function RDBMS()
- {
- if(get_class($this)=='RDBMS'||!is_subclass_of($this)) {
- trigger_error('class RDBMS is an abstract class, cannot instantiate directly',E_USER_ERROR);
- }
- define('RDBMS_LOADED',true);
- }
-
- // Base Function
- // Constructor Declaration
- function _create()
- {
- if(defined('DB_HOST')) $this->hostname = DB_HOST;
- if(defined('DB_USER')) $this->username = DB_USER;
- if(defined('DB_PASS')) $this->password = DB_PASS;
- if(defined('DB_NAME')) $this->database = DB_NAME;
- if(defined('DB_PORT')) $this->port = DB_PORT;
- if(defined('DB_TYPE')) $this->server_type = strtoupper(DB_TYPE);
- $this->log_file = ROOT_DIR.DB_ERROR_LOG; // Put on config.ini.php
- $this->FILE = (PHPVERSION<4.10)?basename(getenv('REDIRECT_URL')):basename($_SERVER['PHP_SELF']);
- $this->start_page = "#"; $this->previous_page = "#"; $this->next_page = "#"; $this->end_of_page = "#";
- eval("$this->navigator = "$this->nav_template";");
- }
-
- // Destructor Declaration
- function _destroy(){
- $this->Close();
- }
-
- // Common Functional
- function Connect(){}
- function TestConnection($dbname,$dbhost,$dbuser,$dbpassword){}
- function Select($fields,$table,$exp='',$page='',$limit='',$urlquery=''){}
- function Insert($table,$fields,$values){}
- function Update($table,$value,$exp=''){}
- function Delete($table,$exp=''){}
- function Query($command,$return_result=0){}
-
- // Error Tracking
- function TrackError()
- {
- $this->error = true;
- $REMOTE_ADDR = getenv("REMOTE_ADDR");
- if($this->log_errors) {
- $date = getdate(); $command = (isset($this->command))?$this->command:'none'; $FILE=(empty($this->FILE))?0:$this->FILE; $LINE=(empty($this->LINE))?0:$this->LINE;
- error_log("[".$date['weekday']." ".$date['month']." ".$date['mday']." ".$date['hours'].":".$date['minutes'].":".$date['seconds']." ".$date['year']."] [client ".$REMOTE_ADDR."] [SQL Strings : ".$command."] [FILE:".$FILE.", LINE:".$LINE."] [".$this->error_msg."]rn", 3, $this->log_file);
- }
- $this->ErrorMarkup .= "<table border=0 width="100%" cellspacing=1><tr><td><hr color="#000000" size=1><p><font face="Verdana" size=2><b>FILE :</b> <font color="#FF0000">{$FILE}</font>;<br/><b>LINE :</b> <font color="#FF0000">{$LINE}</font><br>";
- $this->ErrorMarkup .= '<br/><b>ERROR MSG :<br/></b><font color="#0000FF">'.addslashes($this->error_msg).'<br/></font><br/><b>QUERY :<br></b><font color="#0000FF">'.$command.'</font></font></td></tr></table><br/>';
- global $_ERRORS;
- $_ERRORS .= stripslashes($this->ErrorMarkup);
- trigger_error($this->error_msg,E_USER_ERROR);
- }
-
- // Miscellaneous Function
- function Count($fields,$table,$exp='') {}
- function Sum($field,$table,$exp='') {}
- function Max($field,$table,$exp='') {}
- function Min($field,$table,$exp='') {}
- function createNavigator($table,$exp='',$page='',$limit='',$urlquery='',$encode_url_function="",$func_type="php")
- {
- // In case if there is no filtering but there was an order by * asc command
- if(eregi("group by",$table)) {
- $space = explode(" ",$table);
- if(count($space)>1) $table = $space[0];
- }
- // In case there were a field filtering with GROUP BY command
- /*if (eregi("group by",$exp)) {
- $tmp = $this->Query("SELECT * FROM {$table} WHERE {$exp}");
- $this->TotalRecord = (isset($this->RecordCount))?$this->RecordCount:0;
- } else*/
- $this->TotalRecord = $this->Count("*",$table,$exp);
- if($page<2) $page = 1;
- $pages = $this->TotalRecord/$limit;
- $bottom = $page*$limit;
- $upper = $bottom - $limit;
- $stat = is_float($pages);
- if (!$stat) $this->TotalPage = floor($pages);else $this->TotalPage = ceil($pages);
- if($this->TotalPage>$this->HScroll_Limit) {
- if($func_type!='php') {
- $params = explode("&",substr($urlquery,1,strlen($urlquery)));
- if(count($params)>0) {
- for($i=0;$i<count($params);$i++) {
- $param = explode("=",$params[$i]);
- $arrays[] = $param[0].":'{$param[1]}'";
- }
- $jsdata = "result={".implode(",",$arrays)."}";
- }
- }
- $total_group = ceil($this->TotalPage/$this->HScroll_Limit); /* Count Total Group of number */
- $group = ceil($page/$this->HScroll_Limit); /* define current page position in group ex : current page = 18; $this->TotalPage = 20; total_group = 20/10(number/pages); group_start = 18/total_group => this page located at 2nd group ( 11...20 ); */
- $group_start = (integer)($group*$this->HScroll_Limit)-($this->HScroll_Limit-1);
- $group_end = (($group * $this->HScroll_Limit)>$this->TotalPage)?$this->TotalPage:($group * $this->HScroll_Limit);
- //$this->previous_group = ($encode_url_function!='')$this->FILE."?".$encode_url_function("page=".($group_start-1).$urlquery):$this->FILE."?page=".($group_start-1).$urlquery; /* Information for the previous group allocated at arrow link ( < ) */
- $this->previous_group = ($func_type=='php')?($this->FILE.(((trim($encode_url_function)!='')&&($urlquery!=''))?"?".$encode_url_function("page=".($group_start-1).$urlquery):"?page=".($group_start-1).$urlquery)):((((trim($encode_url_function)!='')&&($urlquery!=''))?"javascript:".$encode_url_function."({$jsdata},".($group_start-1).")":$this->FILE."?page=".($group_start-1).$urlquery));
- $this->next_group = ($func_type=='php')?($this->FILE.(((trim($encode_url_function)!='')&&(strlen($urlquery)>0))?"?".$encode_url_function("page=".($group_end+1).$urlquery):"?page=".($group_end+1).$urlquery)):((((trim($encode_url_function)!='')&&(strlen($urlquery)>0))?"javascript:".$encode_url_function."({$jsdata},".($group_end+1).")":$this->FILE."?page=".($group_end+1).$urlquery)); /* Information for the next group allocated at arrow link ( > ) */
- $prev = ($page<=1)?$page:($page-1);
- $this->start_page = ($func_type=='php')?($this->FILE.(((trim($encode_url_function)!='')&&($urlquery!=''))?"?".$encode_url_function("page=1".$urlquery):"?page=1".$urlquery)):((((trim($encode_url_function)!='')&&($urlquery!=''))?"javascript:".$encode_url_function."({$jsdata},1)":$this->FILE."?page=1".$urlquery));
- $this->previous_page = ($func_type=='php')?($this->FILE.(((trim($encode_url_function)!='')&&($urlquery!=''))?"?".$encode_url_function("page=".$prev.$urlquery):"?page=".$prev.$urlquery)):((((trim($encode_url_function)!='')&&($urlquery!=''))?"javascript:".$encode_url_function."({$jsdata},".$prev.")":$this->FILE."?page=".$prev.$urlquery));
- $this->next_page = ($func_type=='php')?((($page+1)>$this->TotalPage)?$this->FILE.(((trim($encode_url_function)!='')&&($urlquery!='')?"?".$encode_url_function("page=".$page.$urlquery):"?page=".$page.$urlquery)):$this->FILE."?".((((trim($encode_url_function)!='')&&($urlquery!=''))?$encode_url_function("page=".($page+1).$urlquery):"page=".($page+1).$urlquery))):((($page+1)>$this->TotalPage)?(((trim($encode_url_function)!='')&&($urlquery!='')?"javascript:".$encode_url_function."({$jsdata},".$page.")":$this->FILE."?page=".$page.$urlquery)):"javascript:".(((trim($encode_url_function)!='')?$encode_url_function."({$jsdata},".($page+1).")":$this->FILE."?page=".($page+1).$urlquery)));
- $this->end_of_page = ($func_type=='php')?($this->FILE.(((trim($encode_url_function)!='')&&($urlquery!=''))?"?".$encode_url_function("page=".$this->TotalPage.$urlquery):"?page=".$this->TotalPage.$urlquery)):((((trim($encode_url_function)!='')&&($urlquery!=''))?"javascript:".$encode_url_function."({$jsdata},".$this->TotalPage.")":$this->FILE."?page=".$this->TotalPage.$urlquery));
- if(($this->TotalPage>1)&&($group_start>1)) $link[] = "<span> <a class="navigator_arrow" href="{$this->previous_group}"><<</a> </span>";
- for($i=$group_start;$i<=$group_end;$i++) $link[] = ($func_type=='php')?(($i==$page)?"<span class="navigator_selected"> {$i} </span>":"<span> <a class="navigator_active" href="{$this->FILE}?".((trim($encode_url_function)!='')&&($urlquery!='')?$encode_url_function("page=".$i.$urlquery):"page=".$i.$urlquery)."">{$i}</a> </span>"):(($i==$page)?"<span class="navigator_selected"> {$i} </span>":"<span> <a class="navigator_active" href="".((trim($encode_url_function)!='')&&($urlquery!='')?"javascript:".$encode_url_function."({$jsdata},".$i.")":$this->FILE."?page=".$i.$urlquery)."">{$i}</a> </span>");
- if(($group_end>1)&&($group_end<$this->TotalPage)) $link[] = "<span> <a class="navigator_arrow" href="{$this->next_group}">>></a> </span>";
- $this->navigator = implode("",$link);
- $this->navNum = $this->navigator;
- eval("$this->navigator = "$this->nav_template";");
- } else {
- if($this->TotalPage>1) {
- if($func_type!='php') {
- $params = explode("&",substr($urlquery,1,strlen($urlquery)));
- if(count($params)>0) {
- for($i=0;$i<count($params);$i++) {
- $param = explode("=",$params[$i]);
- $arrays[] = $param[0].":'{$param[1]}'";
- }
- $jsdata = "result={".implode(",",$arrays)."}";
- }
- }
- $this->start_page = ($func_type=='php')?($this->FILE.(((trim($encode_url_function)!='')&&($urlquery!=''))?"?".$encode_url_function("page=1".$urlquery):"?page=1".$urlquery)):(((((trim($encode_url_function)!='')&&($urlquery!=''))?"javascript:".$encode_url_function."({$jsdata},1)":$this->FILE."?page=1".$urlquery)));
- $this->previous_page = ($func_type=='php')?(($page>1)?$this->FILE.(((trim($encode_url_function)!='')&&($urlquery!=''))?"?".$encode_url_function("page=".($page-1).$urlquery):"?page=".($page-1).$urlquery):$this->FILE.(((trim($encode_url_function)!='')&&($urlquery!=''))?"?".$encode_url_function("page=1".$urlquery):"?page=1".$urlquery)):(($page>1)?(((trim($encode_url_function)!='')&&($urlquery!=''))?"javascript:".$encode_url_function."({$jsdata},".($page-1).")":"?page=".($page-1).$urlquery):(((trim($encode_url_function)!='')&&($urlquery!=''))?"javascript:".$encode_url_function."({$jsdata},1)":$this->FILE."?page=1".$urlquery));
- $this->next_page = ($func_type=='php')?($this->FILE."?".(($page==$this->TotalPage)?(((trim($encode_url_function)!='')&&($urlquery!=''))?$encode_url_function("page=".$page.$urlquery):"?page=".$page.$urlquery):(((trim($encode_url_function)!='')&&($urlquery!=''))?$encode_url_function("page=".($page+1).$urlquery):"page=".($page+1).$urlquery))):("javascript:".(($page==$this->TotalPage)?(((trim($encode_url_function)!='')&&($urlquery!=''))?$encode_url_function."({$jsdata},{$page})":"?page=".$page.$urlquery):(((trim($encode_url_function)!='')&&($urlquery!=''))?$encode_url_function."({$jsdata},".($page+1).")":$this->FILE."page=".($page+1).$urlquery)));
- $this->end_of_page = ($func_type=='php')?($this->FILE.(((trim($encode_url_function)!='')&&($urlquery!=''))?"?".$encode_url_function("page=".$this->TotalPage.$urlquery):"?page=".$this->TotalPage.$urlquery)):((((trim($encode_url_function)!='')&&($urlquery!=''))?"javascript:".$encode_url_function."({$jsdata},".$this->TotalPage.")":$this->FILE."?page=".$this->TotalPage.$urlquery));
- for($i=1;$i<=$this->TotalPage;$i++) $link[] = ($func_type=='php')?(($i==$page)?"<span class="navigator_selected"> {$i} </span>":"<span> <a class="navigator_active" href="{$this->FILE}?".(((trim($encode_url_function)!='')&&($urlquery!=''))?$encode_url_function("page=".$i.$urlquery):"page=".$i.$urlquery)."">{$i}</a> </span>"):(($i==$page)?"<span class="navigator_selected"> {$i} </span>":"<span> <a class="navigator_active" href="javascript:".(((trim($encode_url_function)!='')&&($urlquery!=''))?$encode_url_function."({$jsdata},".$i.")":$this->FILE."?page=".$i.$urlquery)."">{$i}</a> </span>");
- $this->navigator = implode("",$link);
- $this->navNum = implode("",$link);
- eval("$this->navigator = "$this->nav_template";");
- }
- }
- if(!isset($this->navNum)) $this->navNum = "<span class="navigator_selected"> 1 </span>";
- $this->SQL_LIMIT = " LIMIT {$upper},{$limit}"; // Optional on other SQL Server, this commonly used at MySQL
- }
-
- function inherited($command)
- {
- RDBMS::$command();
- }
-
- function isConnected()
- {
- if(isset($this->connected)) return $this->connected; else return false;
- }
-
- function trace($line,$file='')
- {
- $this->LINE = $line;
- if(!empty($file)) $this->FILE = $file;
- }
-
- function getServerVersion(){}
-
- function getFieldsFromObject($obj)
- {
- if(is_array($obj)) {
- if(count($obj)>0) {
- return array_keys(get_object_vars($obj[0]));
- }
- } else if(is_object($obj)) {
- return array_keys(get_object_vars($obj));
- }
- }
-
- function getFieldsFromAssoc($obj,$type='integer')
- {
- if(is_array($obj)) {
- if(count($obj)>0) {
- if(is_array($obj[0]))
- $fields = array_keys($obj[0]); else
- $fields = array_keys($obj);
- for($n=0;$n<count($fields);$n++) {
- if($type=='integer') {
- if(is_int($fields[$n])) $field[] = $fields[$n];
- } else if($type=='string') {
- if(is_string($fields[$n])) $field[] = $fields[$n];
- }
- }
- return $field;
- }
- } else if(is_object($obj)) {
- return array();
- }
- }
-
- function getDataFromObject($obj,$quote='')
- {
- if(is_array($obj)) {
- if(count($obj)>0) {
- if(empty($quote)) {
- return array_values(get_object_vars($obj[0]));
- } else {
- $dat = array_values(get_object_vars($obj[0]));
- for($i=0;$i<count($dat);$i++) $dat[$i] = $quote.$dat[$i].$quote;
- return $dat;
- }
- }
- } else if(is_object($obj)) {
- if(empty($quote)) {
- return array_values(get_object_vars($obj));
- } else {
- $dat = array_values(get_object_vars($obj));
- for($i=0;$i<count($dat);$i++) $dat[$i] = $quote.$dat[$i].$quote;
- return $dat;
- }
- }
- }
-
- function splitSql($sql)
- {
- $sql = preg_replace("/r/s", "n", $sql);
- $sql = preg_replace("/[n]{2,}/s", "n", $sql);
- $lines = explode("n", $sql);
- $queries = array();
- $inQuery = 0;
- $i = 0;
-
- foreach ($lines as $line) {
- $line = trim($line);
-
- if (!$inQuery) {
- if (preg_match("/^CREATE/i", $line)) {
- $inQuery = 1;
- $queries[$i] = $line;
- }
- elseif (!empty($line) && $line[0] != "#") {
- $queries[$i] = preg_replace("/;$/i", "", $line);
- $i++;
- }
- }
- elseif ($inQuery) {
- if (preg_match("/^[)]/", $line)) {
- $inQuery = 0;
- $queries[$i] .= preg_replace("/;$/i", "", $line);
- $i++;
- }
- elseif (!empty($line) && $line[0] != "#") {
- $queries[$i] .= $line;
- }
- }
- }
-
- return $queries;
- }
-
- }
- ?>