Y.P.Y Posted October 23, 2008 Share Posted October 23, 2008 Hello, This is my first MySQL class , but not completed yet. Plz help me to imporve this. Suggestions are welcome . Thanks for help . <? @error_reporting(E_ALL ^ E_NOTICE); if(!extension_loaded('standard')): @exit('Extension Standard not loaded!'); endif; if(!extension_loaded('mysql')): @exit('Extension MySQL not loaded!'); endif; if(!class_exists('YPY_MySQL')): @exit('Class YPY_MySQL not exists!'); endif; @set_magic_quotes_runtime(0); class YPY_MySQL { private $_Prv_Str_Hostname= ''; private $_Prv_Int_Port= 3306; private $_Prv_Str_Databasename= ''; private $_Prv_Str_Username= ''; private $_Prv_Str_Password= ''; private $_Prv_Str_TablePrefix= ''; private $_Prv_Str_Quote= '`'; private $_Prv_Int_ConnectIdentity= -1; private $_Prv_Int_SelectIdentity= -1; private $_Prv_Int_CloseIdentity= -1; private $_Prv_Int_QueryIdentity= -1; private $_Prv_Int_AffectedRowsIdentity= -1; private $_Prv_Ary_MySQLFunctions= array('mysql_connect', 'mysql_pconnect', 'mysql_close', 'mysql_select_db', 'mysql_query', 'mysql_unbuffered_query', 'mysql_error', 'mysql_errno', 'mysql_affected_rows', 'mysql_insert_id', 'mysql_result', 'mysql_num_rows', 'mysql_num_fields', 'mysql_fetch_row', 'mysql_fetch_array', 'mysql_fetch_assoc', 'mysql_fetch_object', 'mysql_data_seek', 'mysql_fetch_field', 'mysql_field_seek', 'mysql_free_result', 'mysql_field_name', 'mysql_field_len', 'mysql_field_type', 'mysql_escape_string', 'mysql_client_encoding', 'mysql_get_client_info', 'mysql_set_charset', 'mysql_db_name', 'mysql_tablename'); private $_Prv_Ary_Result= array(0); public $_Pub_Ary_Event= array(0); public $_Pub_Bln_QueryExcuted; public $_Pub_Bln_RowsAffected; final public function __clone() { return(@exit('Cloning is not allowed.')); } final public function _Initialize($Str_Hostname, $Int_Port= 3306, $Str_Databasename= 'database', $Str_Username= 'root', $Str_Password= '', $Str_TablePrefix= '') { if(!is_string($Str_Hostname) || !is_integer($Int_Port) || !is_string($Str_Databasename) || !is_string($Str_Username) || !is_string($Str_Password) || !is_string($Str_TablePrefix) || strlen((string)$Str_Hostname) > 255 || strlen((string)$Int_Port) > 10 || strlen((string)$Str_Databasename) > 255 || strlen((string)$Str_Username) > 255 || strlen((string)$Str_Password) > 255 || strlen((string)$Str_TablePrefix) > 255 || $this->_Is_Blank($Str_Hostname)) { $this->_Pub_Ary_Event= array('Type'=> 'Warning', 'Description'=> 'Information is not valid.'); return((boolean)false); }; if(!$this->_Is_Blank($Str_TablePrefix) && !@$this->_Is_Valid_Table_Prefix($Str_TablePrefix)) { $this->_Pub_Ary_Event= array('Type'=> 'Warning', 'Description'=> 'Table prefix is not valid.'); return((boolean)false); }; $this->_Initialize= false; $this->_Prv_Str_Hostname= @$this->_Remove_Tag(@strtolower($Str_Hostname)); $this->_Prv_Int_Port= abs(@$this->$Int_Port); $this->_Prv_Str_Databasename= @$this->_Remove_Tag(strtolower($Str_Databasename)); $this->_Prv_Str_Username= @$this->_Remove_Tag($Str_Username); $this->_Prv_Str_Password= @$this->_Remove_Tag($Str_Password); $this->_Prv_Str_TablePrefix= @$this->_Remove_Tag(@strtolower($Str_TablePrefix)); @mysql_close(-1); @mysql_close(0); @mysql_close($this->_Prv_Int_ConnectIdentity); @$this->_Free_Result(); $this->_Prv_Int_ConnectIdentity= -1; $this->_Prv_Int_SelectIdentity= -1; $this->_Prv_Int_CloseIdentity= -1; $this->_Prv_Int_QueryIdentity= -1; $this->_Prv_Int_AffectedRowsIdentity= -1; $this->_Prv_Ary_Result= array(0); $this->_Connect= false; $this->_Close= false; $this->_Select= false; $this->_Pub_Bln_QueryExcuted; $this->_Free_Result= true; $this->_Pub_Bln_RowsAffected; $this->_Initialize= true; return((boolean)$this->_Initialize); } final public function _Connect($Bln_Persistency= false, $Bln_New= true) { if(!$this->_Initialize) { $this->_Pub_Ary_Event= array('Type'=> 'Warning', 'Description'=> 'Information is not initialized.'); return((boolean)false); }; if($Bln_Persistency): $this->_Prv_Int_ConnectIdentity= @mysql_pconnect($this->_Prv_Str_Hostname . ':' . $this->_Prv_Int_Port, $this->_Prv_Str_Username, $this->_Prv_Str_Password) or $this->_Pub_Ary_Event= array('Type'=> 'Error', 'Description'=> 'Unable to connect(Persistency) to database(#' . @mysql_errno($this->_Prv_Int_ConnectIdentity) . ').'); else: $this->_Prv_Int_ConnectIdentity= @mysql_connect($this->_Prv_Str_Hostname . ':' . $this->_Prv_Int_Port, $this->_Prv_Str_Username, $this->_Prv_Str_Password, $Bln_New) or $this->_Pub_Ary_Event= array('Type'=> 'Error', 'Description'=> 'Unable to connect to database(#' . @mysql_errno($this->_Prv_Int_ConnectIdentity) . ').'); endif; $this->_Prv_Int_ConnectIdentity ? $this->_Connect= true : $this->_Connect= false; return((boolean)$this->_Connect); } final public function _Close() { @$this->_Free_Result() ? $this->_Free_Result= true : $this->_Free_Result= false; $this->_Prv_Int_CloseIdentity= @mysql_close($this->_Prv_Int_ConnectIdentity) ? $this->_Prv_Int_ConnectIdentity= -1 : $this->_Pub_Ary_Event= array('Type'=> 'Error', 'Description'=> 'Could not close connection/database(#' . @mysql_errno($this->_Prv_Int_ConnectIdentity) . ').'); $this->_Prv_Int_CloseIdentity ? $this->_Close= true : $this->_Close= false; return((boolean)$this->_Close); } final public function _Select() { if(!$this->_Initialize || !$this->_Connect || $this->_Close) { $this->_Pub_Ary_Event= array('Type'=> 'Warning', 'Description'=> 'Not initialized/Not connected.'); return((boolean)false); }; $this->_Prv_Int_SelectIdentity= @mysql_select_db($this->_Prv_Str_Databasename, $this->_Prv_Int_ConnectIdentity) or $this->_Pub_Ary_Event= array('Type'=> 'Error', 'Description'=> 'Unable to select database(#' . @mysql_errno($this->_Prv_Int_ConnectIdentity) . ').'); $this->_Prv_Int_SelectIdentity ? $this->_Select= true : $this->_Select= false; if($this->_Select) { @$this->_Free_Result(); $this->_Free_Result= true; }; return((boolean)$this->_Select); } final public function _Excute_Query($Str_Query, $Bln_RemoveTag= false, $Bln_Unbuffered= false) { if(!is_string($Str_Query) || $this->_Is_Blank($Str_Query) || !$this->_Is_Ready()) { $this->_Pub_Ary_Event= array('Type'=> 'Warning', 'Description'=> 'Invalid query/Is not ready.'); return((boolean)false); }; @$this->_Free_Result(); $this->_Free_Result= true; $Str_Query= @strval($Str_Query); #$Str_Query= @$this->_Clean_Value($Str_Query); if($Bln_RemoveTag): @$this->_Remove_Tag($Str_Query); endif; if($Bln_Unbuffered): $this->_Prv_Int_QueryIdentity= @mysql_unbuffered_query($Str_Query, $this->_Prv_Int_ConnectIdentity) or $this->_Pub_Ary_Event= array('Type'=> 'Error', 'Description'=> 'Could not excute unbuffered query(#' . @mysql_errno($this->_Prv_Int_ConnectIdentity) . ').'); else: $this->_Prv_Int_QueryIdentity= @mysql_query($Str_Query, $this->_Prv_Int_ConnectIdentity) or $this->_Pub_Ary_Event= array('Type'=> 'Error', 'Description'=> 'Could not excute query(#' . @mysql_errno($this->_Prv_Int_ConnectIdentity) . ').'); endif; $this->_Prv_Int_QueryIdentity ? $this->_Pub_Bln_QueryExcuted= true : $this->_Pub_Bln_QueryExcuted= false; return($this->_Pub_Bln_QueryExcuted && $this->_Pub_Bln_RowsAffected) ? (boolean)true : (boolean)false; } final public function _Affect_Rows() { if(!$this->_Is_Ready()) { $this->_Pub_Ary_Event= array('Type'=> 'Warning', 'Description'=> 'Is not ready.'); return((boolean)false); }; $this->_Prv_Int_AffectedRowsIdentity= @mysql_affected_rows($this->_Prv_Int_ConnectIdentity) or $this->_Pub_Ary_Event= array('Type'=> 'Error', 'Description'=> 'Could not affect row(s)(#' . @mysql_errno($this->_Prv_Int_ConnectIdentity) . ').'); $this->_Prv_Int_AffectedRowsIdentity ? $this->_Pub_Bln_RowsAffected= true : $this->_Pub_Bln_RowsAffected= false; return((boolean)$this->_Pub_Bln_RowsAffected); } final public function _Free_Result() { @mysql_free_result($this->_Prv_Int_QueryIdentity) ? $this->_Free_Result= true : $this->_Free_Result= false; if(!$this->_Free_Result): $this->_Pub_Ary_Event= array('Type'=> 'Error', 'Description'=> 'Unable to free query result.'); endif; return((boolean)$this->_Free_Result); } final private function _Clean_Table_Name($Str_Input) { if(!is_string($Str_Input) || $this->_Is_Blank($Str_Input)): return((boolean)false); endif; get_magic_quotes_gpc() ? $Str_Input= @stripslashes($Str_Input) : $Str_Input= @addslashes($Str_Input); if(function_exists('mysql_real_escape_string')): @mysql_real_escape_string($Str_Input, $this->Int_QueryIdentity); else: @mysql_escape_string($Str_Input); endif; return((string)@htmlspecialchars($Str_Input)); } final private function _Clean_Value($Str_Input) { get_magic_quotes_gpc() ? $Str_Input= @stripslashes($Str_Input) : $Str_Input= @addslashes($Str_Input); if(function_exists('mysql_real_escape_string')): @mysql_real_escape_string($Str_Input, $this->Int_QueryIdentity); else: @mysql_escape_string($Str_Input); endif; return((string)$Str_Input); } final private function _Remove_Tag($Str_Input) { if(!is_string($Str_Input) || $this->_Is_Blank($Str_Input)): return((boolean)false); endif; $Str_Input= @strip_tags($Str_Input); $_Ary_TagsList= array('jav
ascript:', 'jav
ascript:', 'jav	ascript:', 'JaVaScRiPt:', 'JAVASCRIPT:', '<script>', '<script >', '</script>', '<!-', '<', '>', '%3C', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<','<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '\x3c', '\x3C', '\u003c', '\u003C', chr(60), chr(62)); $Str_Input= @str_replace($_Ary_TagsList, '', $Str_Input); return((string)$Str_Input); } final private function _Is_Valid_Table_Prefix($Str_Input) { return(preg_match('|[^a-zA-Z0-9_]|i', $Str_Input) ? (boolean)true : (boolean)false); } final private function _Is_Ready() { return($this->_Initialize && $this->_Connect && $this->_Prv_Int_ConnectIdentity && !$this->_Close && $this->_Select) ? (boolean)true : (boolean)false; } final private function _Throw_Event() { } final private function _Is_Blank($Str_Input) { return(empty($Str_Input) || is_null($Str_Input) || strlen((string)$Str_Input) <= 0) ? (boolean)true : (boolean)false; } }; ?> [attachment deleted by admin] Link to comment Share on other sites More sharing options...
trq Posted October 23, 2008 Share Posted October 23, 2008 You might start by indenting it so its readable. Link to comment Share on other sites More sharing options...
Recommended Posts