Merhaba arkadaşlar,

Hazırlamakta olduğum mysql sınıfında şuanlık temel özellikleri ekledim fakat daha başka neler olabilir düşüncelerinizi alabilir miyim ?

Sınıf;

class MySQL
{
protected $vt_link;
protected $vt_hostname;
protected $vt_username;
protected $vt_password;
protected $vt_database;
protected $vt_charset;

protected $vt_sql;
protected $vt_sql_sentence;

protected $vt_result;
protected $vt_result_info;

protected $vt_cache_status;
protected $vt_cache_time;
protected $vt_cache_file;

protected $vt_file_path;


public function __construct(array $settings)
{
$this->vt_hostname = $settings[0];
$this->vt_username = $settings[1];
$this->vt_password = $settings[2];
$this->vt_database = $settings[3];
$this->vt_charset = $settings[4];
$this->vt_file_path = $settings[5];

$this->connect();

$this->vt_charset = strtoupper($this->vt_charset);

$this->query("SET NAMES '".$this->vt_charset."'");
$this->query("SET character_set_connection = '".$this->vt_charset."'");
$this->query("SET character_set_client = '".$this->vt_charset."'");
$this->query("SET character_set_results = '".$this->vt_charset."'");
}

public function __destruct()
{
if( $this->vt_link )
{
mysql_close($this->vt_link);
$this->vt_link = null;
return;
}
}

public function connect()
{
$this->vt_link = mysql_connect($this->vt_hostname, $this->vt_username, $this->vt_password);
if( ! $this->vt_link ) return;
if( ! $this->select_db() ) return;
return true;
}

public function select_db()
{
if( is_null($this->vt_link) ) return;
if( ! mysql_select_db($this->vt_database, $this->vt_link) ) return;
return true;
}

public function ping()
{
if( ! mysql_ping($this->vt_link) ) return;
return true;
}

public function query($query, $cache_time = null)
{
$this->vt_sql_sentence = preg_replace("/\s\s+|\t\t+/", " ", trim($query));
$this->vt_sql_sentence = $this->_clean_query($this->vt_sql_sentence);
$this->vt_sql = mysql_query($this->vt_sql_sentence);
if( ! $this->vt_sql ) return;
if( preg_match("/^(select|SELECT|show|SHOW)\s/i", $this->vt_sql_sentence) )
{
$this->vt_cache_time = $cache_time;
if( $this->_is_available_cache() )
{
if( mysql_num_rows($this->vt_sql) > 0 )
{
$this->vt_result = $this->_read_cache();
return $this->vt_result;
}
}
else
{
if( mysql_num_rows($this->vt_sql) > 0 )
{
while( $line = mysql_fetch_assoc($this->vt_sql) )
{
$this->vt_result[] = $line;
}
$this->_write_cache();
return (array) $this->vt_result;
}
}
}
else
{
$this->vt_result_info['insert_id'] = mysql_insert_id($this->vt_link);
$this->vt_result_info['affected_rows'] = mysql_affected_rows($this->vt_link);
$this->vt_result_info['last_query'] = $this->vt_sql_sentence;
return (array) $this->vt_result_info;
}
}

protected function _clean_query($query)
{
if( is_null($query) ) return 'null';
if( is_numeric($query) ) return $query;
if( get_magic_quotes_gpc() )
{
$query = stripslashes($query);
}
if( function_exists("mysql_real_escape_string") )
{
mysql_real_escape_string($query, $this->vt_link);
}
else
{
$query = addslashes($query);
}
return $query;
}

protected function _save_file($path, $data)
{
$handler = fopen($path, 'a');
fwrite($handler, $data);
fclose($handler);
}

protected function _is_available_cache()
{
if( $this->vt_cache_time == 0 ) return false;
if( ! preg_match("/^(select|show)\s/i", $this->vt_sql_sentence) ) return false;
$this->vt_cache_file = $this->vt_file_path.md5($this->vt_database.strtolower($this->vt_sql_sentence)).'.cache';
if( ! file_exists($this->vt_cache_file) ) return false;
if( time() - filemtime($this->vt_cache_file) > $this->vt_cache_time )
{
unlink($this->vt_cache_file);
return false;
}
return true;
}

protected function _write_cache()
{
$this->_save_file($this->vt_cache_file, serialize($this->vt_result));
return;
}

protected function _read_cache()
{
$data = unserialize(file_get_contents($this->vt_cache_file));
return $data;
}
}

?>


Ek Olarak: önbellekleme sistemi entegre edildi.