Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Universal database connection in PHP

Is there some way of building a PHP application that can either connect to a MySQL or Oracle DB without having to change DB connection and query functions if the database changes to/from MySQL/Oracle?

My initial thoughts are 'no'. Surely a PHP DB connection needs to be different for different DB types. However, there might be some function haven't heard about that attempts to connect to a DB in different ways.

Any thoughts would be great. I have a PHP application that connects to a MySQL database on my machine but due to company policy, they only offer Oracle DBs so I'm going to have to change things.

Thank you.

like image 217
ale Avatar asked Jun 23 '26 00:06

ale


2 Answers

Yes. It's called a Database Abstraction Layer. Have a look at PDO, it comes bundled with PHP.

like image 70
Rijk Avatar answered Jun 25 '26 15:06

Rijk


Use PDO. You need to ensure that your queries work in both database systems though.

like image 22
ThiefMaster Avatar answered Jun 25 '26 15:06

ThiefMaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!