views:

102

answers:

3

hello,

there are already some applications available which "understand" the mysql protocol and to which it's possible to connect using a mysql client -- for example: you can connect to the sphinx search engine using the (an) mysql client, mysql-proxy understands the mysql-protocol, too. etc.

now i wonder if there is an implementation available in/for PHP so you could connect to some server-application implemented in PHP using the mysql client? i am looking for some PHP library (or extension) which implements the mysql protocol.

thanks, harald

A: 

There are built-in mySQL client functions in PHP: manual

is that what you mean?

Pekka
I think he wants to implement a server, such that any mysql client could connect to it
Paul Dixon
yes, paul is right -- i'm looking of how to implement a server
harald
Right. Well, implementing the mySQL protocol in PHP would be so outlandishly slow that I don't think there is a working product out there. FlorianH's idea of a proxy is probably the closest you can get without actually rewriting the whole thing. May I ask what you want to use this for?
Pekka
yes, i thought of providing an SQL interface for some in php implemented server -- somehow like sphinx search is providing it. when there was a pecl extension for php providing mysql-server-protocol support, that would be nice ...
harald
Ahh I see, you would like to provide a service with custom data, based on the mySQL protocol. Hmm. As I said, PHP is structurally not really the language for this. Isn't there a more fitting protocol to implement your interface in, say one of the stateless web service protocols?
Pekka
i thought it was a nice idea -- at least to start playing around with, if there was such an extension. if it would ever happen to be really part of a final product ... i'm not sure about this. ;-)
harald
Right. Well, you already mention mySQL-Proxy: http://forge.mysql.com/wiki/MySQL_Proxy apart from modifying it to "redirect" all queries to a PHP script, I can't really think of anything....
Pekka
A: 

Do you mean a scenario like: You have a system, that does not have a mysql library but you want to be able to talk to the mysql server. To do that, you want to use PHP as a proxy to talk to the database?

If your existing system can do http requests, you might want to create a restful service in php and access that restfull service. PHPRest might be what you are looking for.

Keep in mind, that this is probably slow, compared to a direct database call.

FlorianH
no, my question was not clear enough -- sorry. i would like to implement a server which is capable of the mysql-server protocol.
harald
+1  A: 

I'm not aware of an existing pure php implementation of a mysql server. I expect it would be slower than a C/C++ counterpart. Additionally, php has always been annoying to run as a daemon.

However, should you wish to implement a server, you may wish to look at http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol. It defines the protocol for client-server communications.

Kazar
yes, you are probably right -- a pure php implementation would be slow. anyway, i'll have a look at the protocol documentation, thanks for the link.
harald
Absolutely correct! PHP stinks to high heaven when it comes to running a listener/deamon. Any time you feel you need a script to run constantly you have stepped beyond what PHP should do and you need to look at other options.
Joe Mills
i don't think that the process control functions of php are _that_ bad. there are limitations, though ...
harald