2

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..

1
  • 1
    +1 for making the effort to switch to pdo. Commented Sep 23, 2012 at 11:33

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

When you replaced $cn=connect(); I switched to $cn=pdoconnect(); - you still have to replace mysql_query() to PDO prepare(), execute() functions right?
You clearly are a very experienced programmer, I would be more than glad to know new ways

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.