What I am about to ask for is quite horrible, I know, still am just weigh my options and this is one of them.
Is there a way to extract/access ONLY the DB connection from a PDO w/o going through a PDOStatement?
A while back, in my novice student days, I wrote a CMS script using procedural PHP and mysli functions.
mysqli_connect($host,$UserAcc,$pass)
Sometime later , in my novice days, I was able to streamline my code ( with minimal work ) by using a singleto/registry pattern to store my DB handlers. Even though my functions still used mysqli my code automatically reused DBhandles by accessing the registry object’s methods.
function DBconn($host=HOST, $UserAcc=UACC,$pass=UPASS){
$connect= mysqli_connect($host,$UserAcc,$pass);
return $connect;
} // opens DB connection handle
class DBReg{
protected static $conns= array(); // storage for DB connection handles
public static function getConn($n=DBNAME){
if (!isset(self::$conns[$n])){return self::addConn($n);}
return self::$conns[$n] ;
}// returns a DB connection handle from the registry
public static function addConn($n=DBNAME, $UserAcc=UACC,$pass=UPASS,$host=HOST){
self::$conns[$n]=DBconn($host,$UserAcc,$pass);
return self::$conns[$n];
}
}
$db=mysqli_select_db(DBReg::getConn($cn),$cn);
Recently, I rewrote the script to employ PDOs … works great. But I still have to keep the old methods in there for backwards compatibility with old templates that were using procedural or hybrid code.
it occurs to me that I could go back and tweak some of my previous methods/function to act as a shell, returning the same type of data as before but obtain their results from my new PDO driven registry.
THE ISSUE is that the old code expects DB handle and not an actual PDO or PDOStatement, so my question how can I get just the DB connection handle ( the equivalent of mysqli_connect($host,$UserAcc,$pass); ) from a PDO… I need to get just the handle and NOT a PDOStatement or or PDO handle object, that is if that can be done at all.
Thanks in advance!