connecting to a database server using fsockopen or socket functions and issuing commands
How do we connect to a database server using any programming language using socket functions. I am thinking like the protocols. For example smtp, http, ftp, imap. we connect to these ports and we issue comands (execute commands). Like these is it possible to connect to a database server (the port is 3306) and can we issue commands which might 开发者_StackOverflow中文版execute various functionality like DDL, DML, TCL.
Since people say database server i thought of this like there should some possiblity to do to what i think instead of using programming language related sql functions like mysql_connect, mysql_select or mysql_query...
i would like to have suggestions, answers and references. may be i am not using the relevant search string in google to find information for this.
"You don't". Unless a particular service documents its protocol as a public API, this is risky, difficult, and prone to break at any minute. The protocol might even include elements specifically intended to make this hard. You can, of course, wireshark and reverse engineer the protocol, but you never know for sure that the definition does not include 'On september 22nd change all the Q's to R.'
You will need to communicate with the servers using their (custom) protocols.
Why would you want to reimplement these protocols though? Unless this is just academic curiosity, you're much better off using any libraries the DB vendors supply.
The functions you talk about (mysql_connect, mysql_query, ...) are essentially acting on a raw socket, but they know the protocol. They take an SQL query, and they take a socket and they process the query into the right data to send.
Protocols on things like DB servers are going to be non-human readable. The HTTP is pretty and clear compared to a protocol designed for small size and strict parsing. Unless you absolutely need to, I would avoid reinventing the wheel.
精彩评论