NYCPHP Meetup

NYPHP.org

[nycphp-talk] Which MySQL API?

Greg Rundlett (freephile) greg at freephile.com
Tue Feb 25 07:37:52 EST 2014


On Tue, Feb 25, 2014 at 6:55 AM, David Krings <ramons at gmx.net> wrote:

> On 2/24/2014 10:41 PM, justin wrote:
>
>>>>
>> On Mon, Feb 24, 2014 at 7:34 PM, David Krings <ramons at gmx.net
>> <mailto:ramons at gmx.net>> wrote:
>>
>>     Regular MySQL depricated? Can anyone elaborate on this? Is that to be
>>     understood as that the drivers for MySQL in PHP will go away
>> eventually?
>>
>>
>> The "regular" MySQL library has been deprecated, meaning all of the
>> functions
>> that start with mysql_*
>>
>>
> Thanks for the pointers. After some top level cursory reading the new
> means seem to do the same, just with a more complicated syntax (bleah!).
> This might be not the right place to ask, but why depricate the MySQL
> library? I could understand if MySQL usage was close to zero, but it
> remains a popular RDBMS.
>
> Just wondering, because my son asked me how to make a web form that
> connects to a database and I rather not teach him stuff that is about to be
> obsolete.


Just for clarity: MySQL the database is not going away.  (Well, MariaDB -
the free software fork - is making good strides at replacing it.)

PHP has always used an API (think "wrapper") to interface with the MySQL
database, as it is with all the other databases that you can connect PHP
to.  The "new" (improved) API for the MySQL database is called MySQLi.
 Similarly, there is also an improved library which the API talks to.  It's
the library that actually does all the work of interfacing with the
database.  By default, you get the new library with recent versions of PHP.
 You can still choose which API to use (and choose which underlying library
as well), however the oldest, original API is not maintained and will be
removed.

I like this quote from one observer who commented in the manual:
"Apart from the feature list, I suggest you try out both MySQLi and PDO and
find out what API design you like most. MySQLi is more powerful and
probably more complex to learn. PDO is more elegant and has the advantage
that you only need to learn one PHP API if you need to work with different
DBMS in the future."

To explain that just a little: "MySQLi is more powerful" means that because
it is designed with one database in mind, it offers the fullest feature set
to match the capabilities of the underlying library and database.

PDO is an API that comes with drivers for multiple databases, and so it
touts the advantage of allowing you to easily switch databases with almost
no code changes should that future need arise.  There are plenty of
database-specific optimizations that can cause you to choose one database
platform over another so the theory of switching databases at will seems a
bit specious in practice.

Greg Rundlett
http://eQuality-Tech.com <http://equality-tech.com/>
http://freephile.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20140225/ca572f28/attachment.html>


More information about the talk mailing list