website built using MySQL how to upgrade to PDO?


We have a website built under PHP and MySQL however my colleague have used the MySQL I heard that PDO or MySQLi is better and safer. So how do we change it? Just use PDO directly instead of using the old way of connecting to the database? Could you show some script or at least give me some idea on how to do it? Do we need to change anything on the database?

Kind Regards,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
The database does not need to be changed.  The 'mysql' functions need to be re-written with either the 'mysqli' or PDO functions.  You can do this one page at a time, you don't need to replace all of the pages at once.  

One major difference is that any 'mysql' functions used inside PHP functions require special attention.  The old 'mysql' connections are 'superglobal' and always available inside PHP function but the 'mysqli' connections are variables and Not automatically available.  You may have to declare them as 'global' inside your functions.
prinLeAAuthor Commented:

You mentioned that the mysqli connections are variables and Not automatically available and may need to be declare as global inside the functions. How about in PDO? is it the same? I think we will be using PDO. From what I can understand PDO is a way for you to connect to your database and if we use PDO do we need to change anything? like what you mentioned above in mysqli that may need to be declare as global inside the functions.

Kind Regards,
Dave BaldwinFixer of ProblemsCommented:
All these things are documented on the pages.

mysqli -



It appears that the PDO connection info is a variable also.

There are many things that are different from 'mysql' so you really need to read those pages to see what to do.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prinLeAAuthor Commented:
Thanks I really appreciate your help. I also found some links here at Expert Exchange that are very helpful to me.
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.