user = $user; $this -> pass = $pass; $this -> dbhost = $dbhost; $this -> dbname = $dbname; } public function __destruct(){ if($this -> dbh){ mysql_close($this -> dbh); } } public function connect(){ $this -> dbh = mysql_connect($this -> dbhost, $this -> user, $this -> pass); if(!is_resource($this -> dbh)){ throw new Exception("A kapcsolódás a MySQL szerverhez sikertelen!"); } if(!mysql_select_db($this -> dbname, $this -> dbh)){ throw new Exception("A(z) $this->dbname adatbázis nem létezik!"); } mysql_query("SET NAMES utf8", $this -> dbh); } public function getdbname(){ return $this -> dbname; } } class db_mysql extends connect_mysql{ public $query; private $_binds; private $_result; public function __construct($user, $pass, $dbhost, $dbname){ parent :: __construct($user, $pass, $dbhost, $dbname); $this -> query = ""; $this -> _binds = array(); $this -> _result = false; } public function execute(){ if(!$this -> dbh){ $this -> connect(); } $binds = func_get_args(); foreach($binds as $index => $name){ if(get_magic_quotes_gpc()){ $this -> _binds[$index + 1] = stripslashes($name); }else{ $this -> _binds[$index + 1] = $name; } } $query = $this -> query; foreach($this -> _binds as $key => $value){ $query = str_replace(":$key#", "'" . mysql_real_escape_string($value, $this -> dbh) . "'", $query); } $this -> _result = mysql_query ($query, $this -> dbh); if(!$this -> _result){ throw new Exception("Az SQL utasítás végrehajtása sikertelen! " . mysql_error($this -> dbh)); } } public function fetch_row(){ if(!$this -> _result){ throw new Exception("Az SQL utasítás nincs végrehajtva!"); } if(!is_resource($this -> _result)){ throw new Exception("A függvény csak a Select utasítás által szolgáltatott eredményhalmazra alkalmazható!"); } return mysql_fetch_row($this -> _result); } public function fetch_assoc(){ if(!$this -> _result){ throw new Exception("Az SQL utasítás nincs végrehajtva!"); } if(!is_resource($this -> _result)){ throw new Exception("A függvény csak a Select utasítás által szolgáltatott eredményhalmazra alkalmazható!"); } return mysql_fetch_assoc($this -> _result); } public function num_rows(){ if(!$this -> _result){ throw new Exception("Az SQL utasítás nincs végrehajtva!"); } if(!is_resource($this -> _result)){ throw new Exception("A függvény csak a Select utasítás által szolgáltatott eredményhalmazra alkalmazható!"); } return mysql_num_rows($this -> _result); } public function data_seek($row){ if(!$this -> _result){ throw new Exception("Az SQL utasítás nincs végrehajtva!"); } if(!is_resource($this -> _result)){ throw new Exception("A függvény csak a Select utasítás által szolgáltatott eredményhalmazra alkalmazható!"); } mysql_data_seek($this -> _result, $row); } public function fetchall_row(){ $retval = array(); while($row = $this -> fetch_row()){ $retval[] = $row; } return $retval; } public function fetchall_assoc(){ $retval = array(); while($row = $this -> fetch_assoc()){ $retval[] = $row; } return $retval; } public function num_fields(){ if(!$this -> _result){ throw new Exception("Az SQL utasítás nincs végrehajtva!"); } if(!is_resource($this -> _result)){ throw new Exception("A függvény csak a Select utasítás által szolgáltatott eredményhalmazra alkalmazható!"); } return mysql_num_fields($this -> _result); } public function field_name($n){ if(!$this -> _result){ throw new Exception("Az SQL utasítás nincs végrehajtva!"); } if(!is_resource($this -> _result)){ throw new Exception("A függvény csak a Select utasítás által szolgáltatott eredményhalmazra alkalmazható!"); } return mysql_field_name($this -> _result, $n); } public function affected_rows(){ if(!$this -> _result){ throw new Exception("Az SQL utasítás nincs végrehajtva!"); } return mysql_affected_rows(); } } ?>