On the existing system its use old MySQL functions.. I would like to replace it all to PDO but it would take a long time and a lot of testing.
Is it possible to mix PDO and MySQL Functions on the existing system? For example new pages/php files will use PDO... All the old files will still use old MySQL for time being and will be replaced slowly as system will continue to update..
Yes, it is perfectly fine to use both at the same time. Keep in mind, though, that you would need a seperate connection for either type and beware of the implications that arise from such an approach.
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.