Standard connection libraries for MySQL, MSSQL and Oracle in PHP

I am looking for a standard way to connect to databases in PHP. We were all there - first we start with some elementary code to connect / query / iterate / insert / disconnect, then the code grew as the program grew, and as a result it was a mess that can hardly be reused.

I know that there are many PEAR, PECL, and other PHP libraries / classes that can fit my description, but which of them are supported, used, and proven to be error-free and efficient?

+4
source share
5 answers

I am surprised Zend_Db has not been mentioned yet ...

  • PEAR MDB2 : very stable, also provides a layer that implements all the supported MDB2 functions in all databases, where it can at least be simulated. I have used this year for many years with great success.
  • Zend Framework Zend_Db : I just started using the higher levels of the entire Zend database infrastructure, but it seems to be pretty stable and very well designed.
  • PHP5 native PDO : I haven't used it at all, but I find this to be the easiest of all. In fact, both MDB2 and Zend_Db can use PDO as their base layer.

All of the above preparation and implementation tools. From the above, MDB2 is the most mature since it has existed for a long time and is based on DB and MDB. Zend_Db looks the most well thought out. I know that there are others, but I have no experience or any knowledge of them.

+2
source

if you are using PHP 5 try PDO

+6
source

try object relational mapping libraries like Propel and Doctrine , both use PDOs as the database abstraction layer, so they pretty much work on all engines.

+2
source

These two are the best in my opinion. I can't claim to have tried them all though :)

If on Linux you need FreeTDS to connect to MSSQL, regardless of which library you choose.

+1
source

When we look at new DB connection / query objects, trying to decide who to write to or use new libraries for, we decided it was better to write our own. In the end, it probably does not have the flexibility available to many other libraries, but we added functions such as GetAll() , which extracts all the rows in the array with keys or GetAllKeyed() , which returns an array with the key with the identifier as key . Another great GetOne() option to use when your selection has only 1 column. All this significantly reduced the amount of code.

Another feature is that when you execute a query, it determines what type of query it is ( INSERT , UPDATE , SELECT , DELETE , etc.), and then returns the relevant information (for example, INSERT , last insert identifier, or DELETE number of rows deleted).

But we also copied features like Prepare and Execute from PEAR: DB.

+1
source

Source: https://habr.com/ru/post/1277480/


All Articles