[ alfa-pro @ 15.11.2012. 16:33 ] @
Radim db classu i sada kada izgubim konekciju zelim da se automatcki rekonektuje za to koristim mysql_ping. Sada ja zelim da testiram jel radi uopste taj reconnect. Jel postoji neki nacin da prekinem konekciju i da vidim oce li se automacki konektovati? Dajte mi neki predlog. Eo deo mog koda Code: <?php class Database { private $db_name; private $db_user; private $db_pass; private $db_host; public $reconnect = TRUE; public $connect = TRUE; /*------------------------------------------------ * Database Constructor **------------------------------------------------ */ public function __construct() { if($this->connect == TRUE) { $this->db_host = DB_HOST; $this->db_user = DB_USER; $this->db_pass = DB_PASS; $this->db_name = DB_NAME; $this->connect($this->db_host, $this->db_user, $this->db_pass); $this->db_select($this->db_name); } } /*------------------------------------------------ * Database Connection *------------------------------------------------ * Open a connection to a MySQL Server * @db_host, $db_user, $dp_pass */ public function connect($db_host, $db_user, $db_pass) { if($this->connect == TRUE) { $this->connect = mysql_connect($db_host, $db_user, $db_pass); if(!$this->connect){ throw new Exception('Database connection eorrr #1'); } if(!mysql_ping($this->connect)){ throw new Exception('Database connection #ID('.mysql_thread_id($this->connect).') is lost'); $this->reconnect(); } } } /*------------------------------------------------ * Select Database *------------------------------------------------ * Select a MySQL database * * Returns TRUE on success or FALSE on failure. */ public function db_select($db_name) { $database = mysql_select_db($db_name, $this->connect); if(!$database) { throw new Exception($db_name.' database not exists'); } } /*------------------------------------------------ * Database Close *------------------------------------------------ * Close MySQL connection * * Returns TRUE on success or FALSE on failure. */ public function disconect() { if(isset($this->connect)){ mysql_close($this->connect); unset($this->connect); } } /*------------------------------------------------ * Database Reconnect *------------------------------------------------ * Returns TRUE if the connection to the server - * MySQL server is working, otherwise FALSE. */ public function reconnect() { if($this->reconnect == TRUE) { $this->disconect(); $this->connect($this->db_host, $this->db_user, $this->db_pass); $this->db_select($this->db_name); } } } ?> [Ovu poruku je menjao alfa-pro dana 15.11.2012. u 17:44 GMT+1] |