PHP: Managing Connection Pools in Object-Oriented Approach?

The correct approach seems to be to use a singleton-based database class as such: class Database { protected $conn; protected $dbstr; // keep the one and only instance of the Database object in this variable protected static $instance; // visibility changed from public to private to disallow dynamic instances private function __construct() { $this->conn = null; $this->dbstr = "jndi connection string"; $this->connect(); } // added this method public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new Database(); } return self::$instance; } // everything below this comment is as it was; I made no changes here public function connect(){ try{ $this->conn = new PDO($this->dbstr); // Used with jndi string } catch (PDOException $e){ // print $e->getMessage(); } return ""; } public function insert($query, $data){ try{ $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /* Execute a prepared statement by passing an array of values */ $sth = $this->conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $count = $sth->execute($data); return $this->oracleLastInsertId($query); }catch(PDOException $e){ throw new Exception($e->getMessage()); } } public function oracleLastInsertId($sqlQuery){ // Checks if query is an insert and gets table name if( preg_match("/^INSERT\t\n +INTO\t\n +(a-z0-9\_\-+)/is", $sqlQuery, $tablename) ){ // Gets this table's last sequence value $query = "select ". $tablename1. "_SEQ.

Currval AS last_value from dual"; try{ $temp_q_id = $this->conn->prepare($query); $temp_q_id->execute(); if($temp_q_id){ $temp_result = $temp_q_id->fetch(PDO::FETCH_ASSOC); return ( $temp_result )? $temp_result'LAST_VALUE' : false; } }catch(Exception $err){ throw new Exception($err->getMessage()); } } return false; } public function close(){ $this->conn = null; } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions