2

i will connect to mysql witout mysql_connect but have an error :)

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://example.com:3306');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$fields = "user=root&pass=";
curl_setopt($curl_handle,CURLOPT_POST, count($fields));
curl_setopt($curl_handle,CURLOPT_POSTFIELDS, $fields);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)){
    print "Nothing returned from url.<p>";
}
else{
    print $buffer;
}

has error like

5.5.27)500>)P7cÿ÷€n|I3cxQnVC,Omysql_native_password!ÿ„#08S01Got packets out of order

baravak
  • 33
  • 1
  • 1
  • 5

1 Answers1

3

The protocol to communicate with MySQL is not HTTP, so you cannot use an HTTP client like cURL.

If you want to use sockets directly, then start with the PHP sockets library (the first thing you should do is to open a connection.

Then you'll need to implement the MySQL protocol, which is described in the manual.

That said, while you shouldn't use mysql_, there are good replacement libraries that exist already.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335