I am new to SO but I have faced this problem too. Many people find it troublesome to switch from mysql_*
to PDO.
In my case I was using a separate connection.php
that stored functions to connect to database and returned the handle
function connect()
{
$cn = mysql_connect("localhost","username","pass" );
$select = mysql_select_db("dbname", $cn);
return($cn);
}
//For PDO
function pdoconnect()
{
$db="";
try
{
$db=new PDO("mysql:host=localhost;dbname=dbname", "username", "pass");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $er)
{
print("errr".$er."<br />");
return(1);
}
return($db);
}
while for old functions I used $cn=connect();
.
I switched to $cn=pdoconnect();
for new ones.
This worked because I was already using connect.php
in old files as well.