Thursday, December 27, 2007

Idea for "pure" mysqlnd interface

When I first heard about the mysqlnd project at the MySQL Camp in 2006, somehow I thought it was going to be 100% PHP code. I can't remember now if I was making an incorrect assumption or if they planned to write it in PHP but changed their mind.

What we have today is a DLL that is a drop-in replacement for libmysql. This has a few nice advantages. It means the replacement library will be API-compatible with all three PHP extensions for MySQL, (mysql, mysqli, and pdo_mysql) so it requires no one to change their PHP application code. The libmysqlnd is licensed under the PHP license, so it can be distributed with PHP core without any license conflict. All in all a good solution that will help both PHP and MySQL.

But what about my (mistaken) impression of a MySQL client written in PHP, instead of implemented as a DLL? Essentially this would implement in PHP code the MySQL client/server protocol.

It's certainly possible that implementing this protocol in a language like PHP would be hopelessly inefficient and not suitable for any real world development. But it would have a few nice advantages:
  • Providing a platform-independent MySQL client.
  • Deploying easily in hosting environments with no access to configure php.ini.
  • Allowing PHP debugging tools to inspect at the protocol level.
  • Serving as a model for similar drivers for Perl, Ruby, Python, etc.
  • Licensing with the same license as the respective language, e.g. PHP License, Artistic License, or GPL.

Writing a driver in the host language has precedent. A JDBC type 4 driver is supposed to implement the vendor's client/server protocol in 100% Java code, so as to appear to the RDBMS server as indistinguishable from the vendor's own client library.

So for now, this is just an idle idea. Please don't anyone ask me where to download this imaginary software, it doesn't exist as far as I know!


doughboy said...

The performance of such an animal would be really bad. And since almost no server with PHP is deployed without the MySQL extension(s) I see not use for such a thing.

Do you see some advantages?

jim said...

and such drivers already exist for perl, python (although not released yet), and ruby. php is behind the times here.