我将使用mysql_connect连接到mysql 但有一个错误:)
$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;
}
有错误,如
5.5.27)500&gt;)P7cÿ÷€n | I3cxQnVC,Omysql_native_password!ÿ“#08S01Got数据包无序
答案 0 :(得分:1)
与MySQL通信的协议不是HTTP,因此您不能使用像cURL这样的HTTP客户端。
如果您想直接使用套接字,请从PHP sockets library开始(您应该做的第一件事就是open a connection。
然后您需要实施the MySQL protocol, which is described in the manual。
尽管如此,虽然you shouldn't use mysql_
已经good replacement libraries that exist了。