PHP Classes

File: dbsearchclass.php

Recommend this page to a friend!
  Classes of markitos   dbsearch   dbsearchclass.php   Download  
File: dbsearchclass.php
Role: ???
Content type: text/plain
Description: dbsearch class/clase dbsearch
Class: dbsearch
Author: By
Last change:
Date: 23 years ago
Size: 8,955 bytes
 

Contents

Class file image Download
<? class dbsearch { var $_Pattern; var $_DbName; var $_DbUser; var $_DbPass; var $_DbHost; var $_PortServer; var $_DbLink; var $TablesName = array (); var $NumResult; var $FindStart; var $_IdFindPerTable = array (); Function dbsearch ($DbNameValue, $UserDbValue, $PassDbValue, $HostDbValue, $PortServerValue) { if ((!$DbNameValue)||(!$UserDbValue)||(!$PassDbValue)||(!$HostDbValue)){return FALSE;} if (!(eregi ("[0-9]{1,}",$PortServerValue))){$PortServerValue=3306;} $this->DbName ($DbNameValue); $this->DbUser ($UserDbValue); $this->DbPass ($PassDbValue); $this->DbHost ($HostDbValue); $this->PortServer ($PortServerValue); $this->FindStart = 0; $this->NumResult = 0; $this->_Pattern = ''; return TRUE; } Function OpenConnection() { $this->DbLink (mysql_connect ($this->DbHost('').":".$this->PortServer(''),$this->DbUser(''),$this->DbPass(''))); if (!$this->DbLink('')){return FALSE;} if (!mysql_select_db ($this->DbName(''),$this->DbLink(''))){ $this->CloseConnection(); return FALSE; } $TablesQuery = mysql_list_tables ($this->DbName(''), $this->DbLink('')); for ($Counter = 0; $Counter < mysql_num_rows ($TablesQuery); $Counter++){ array_push ($this->TablesName, mysql_tablename ($TablesQuery, $Counter)); } unset ($Counter); unset ($TablesQuery); if ((count ($this->TablesName))<1){return FALSE;} return TRUE; } Function CloseConnection() { if ($this->DbLink('')){mysql_close ($this->DbLink(''));} return TRUE; } Function EndSearch() { $this->CloseConnection(); unset ($this); return TRUE; } Function FormatString ($PatternValue) { $PatternValue = ltrim ($PatternValue); $PatternValue = rtrim ($PatternValue); $PatternValue = htmlentities ($PatternValue); $PatternValue = eregi_replace ("[ ]{1,}"," ",$PatternValue); return $PatternValue; } Function NumResult() { if (!$this->FindStart){ return FALSE;} if ($this->NumResult <1 ){ return "none";} return $this->NumResult; } Function SetPattern ($NewPatternValue) { if (!$this->DbLink('')){return FALSE;} $this->FindStart = 0; $this->NumResult = 0; if (!$NewPatternValue){ return FALSE;} $NewPatternValue = $this->FormatString ($NewPatternValue); if ((strlen ($NewPatternValue))<=1){ return FALSE;} $this->Pattern ($NewPatternValue); return TRUE; } Function FindInDb ($FullWord, $IsCase, $ExcludeTables) { $this->NumResult = 0; $this->FindStart = 0; if ((!$this->DbLink(''))||(strlen($this->Pattern(''))<1)||(count($this->TablesName)<1)){ return FALSE;} $this->FindStart = 1; $CheckExcludes=$NoInclude=0; if (is_array ($ExcludeTables)){$CheckExcludes=1;} $FieldsName = array (); while (list ($null,$TableName) = each ($this->TablesName)){ if ($CheckExcludes==1){ while (list ($null,$Exclude) = each ($ExcludeTables)){ if ($Exclude==$TableName){$NoInclude=1;break;} } reset ($ExcludeTables); } if ($NoInclude==1){$NoInclude=0;continue;} $FieldsName{$TableName}= array (); $FieldsQuery = mysql_query ("SHOW FIELDS FROM $TableName"); while ($QueryResult = mysql_fetch_array ($FieldsQuery)){ if ($QueryResult{'Field'} != 'id'){ array_push ($FieldsName{$TableName},$QueryResult{'Field'}); } } } unset ($FieldsQuery); unset ($QueryResult); unset ($TableName); $DataResults = array (); while (list ($TableName, $ATTable) = each ($FieldsName)){ $DataResults{$TableName} = array (); $SQLTable = "SELECT id"; while (list ($null, $FieldName) = each ($ATTable)){ $SQLTable .= ",".$FieldName; } $SQLTable .= " FROM $TableName WHERE 1"; $TableQuery = mysql_query ($SQLTable); if (!$TableQuery){ continue; } while ($QueryResult = mysql_fetch_array ($TableQuery)){ while (list ($null,$FieldNombre) = each ($FieldsName{$TableName})){ if (strlen ($QueryResult{$FieldNombre})<1){ continue;} if (isset ($NewFound)){unset ($NewFound);} $EvalEreg = "if (ereg"; if (!$IsCase){ $EvalEreg .= 'i';} $EvalEreg .= " (\""; if ($FullWord){ $EvalEreg .= '^';} $EvalEreg .= $this->Pattern (''); if ($FullWord){ $EvalEreg .= '$';} $EvalEreg .= "\", \$QueryResult{\$FieldNombre})){ array_push (\$DataResults{\$TableName}, \$QueryResult{'id'});}"; eval ($EvalEreg); } reset ($FieldsName{$TableName}); } } reset ($this->TablesName); reset ($DataResults); $this->_IdFindPerTable = $DataResults; $this->NoDuplis(); return TRUE; } Function NoDuplis() { $Is = $NoIs = 0; $COPY = $this->_IdFindPerTable; $VISTOS = array (); while (list ($null, $tbname) = each ($this->TablesName)){ $VISTOS{$tbname}=array(); } $NUEVO = $VISTOS; while (list ($tabla, $array) = each ($COPY)){ while (list ($null, $id) = each ($array)){ $Is = 0; if (count ($VISTOS{$tabla})<1){$NoIs=1;}else{ $NoIs = 0;} while (list ($n, $idd) = each ($VISTOS{$tabla})){ if ($id==$idd){ $NoIs=0; $Is=1; break; } $NoIs=1; $Is=0; } if ($NoIs==1){ array_push ($NUEVO{$tabla}, $id); array_push ($VISTOS{$tabla}, $id); $this->NumResult++; } reset ($VISTOS); } } reset ($this->TablesName); $this->_IdFindPerTable=$NUEVO; } Function GetDataId ($TableNameValue, $FieldsNameValue, $IdValue) { $SQLData = "SELECT $FieldsNameValue FROM $TableNameValue WHERE id='$IdValue'"; $QueryData = mysql_query ($SQLData, $this->DbLink('')); return (mysql_fetch_array ($QueryData)); } Function DbName ($DbNameValue) { if (!$DbNameValue){ return $this->_DbName;} return ($this->_DbName = $DbNameValue); } Function DbUser ($DbUserValue) { if (!$DbUserValue){ return $this->_DbUser;} return ($this->_DbUser = $DbUserValue); } Function DbPass ($DbPassValue) { if (!$DbPassValue){ return $this->_DbPass;} return ($this->_DbPass = $DbPassValue); } Function DbHost ($DbHostValue) { if (!$DbHostValue){ return $this->_DbHost;} return ($this->_DbHost = $DbHostValue); } Function PortServer ($PortServerValue) { if (!$PortServerValue){ return $this->_PortServer;} return ($this->_PortServer = $PortServerValue); } Function Pattern ($PatternValue) { if (!$PatternValue){ return $this->_Pattern;} return ($this->_Pattern = $PatternValue); } Function DbLink ($DbLinkValue) { if (!$DbLinkValue){ return $this->_DbLink;} return ($this->_DbLink = $DbLinkValue); } Function IdFindPerTable ($DataValue) { return $this->_IdFindPerTable; } } ?>