How to connect to my own server via mysql_connect php function
I want to analyze queries sending to MySQL server. Also program (which sending queries) code should be the same So, here is function to connect to MySQL server:
if (mysql_con开发者_如何转开发nect('127.0.0.1', 'root', '12345')) {
mysql_select_db('db');
} else {
print "connection failed....";
}
I created my own severs with ip 127.0.0.3 and listened port 3303. So, I rewrite this function like this:
if (mysql_connect('127.0.0.3:3303', 'root', '12345')) {
mysql_select_db('db');
} else {
print "connection failed....";
}
When I try to connect my server see a connection, but doesn't receive any data, such as login ('root') and password. So, I can't to connect to MySQL from my server-program
What can be the best solution? Thanks
Well, for one thing, the standard mysql port is 3306. I would check the config file on 127.0.0.3 to make sure that is the port that is set and that there is no firewall blocking that port.
As a guess, I would make sure you have
# skip-networking
in the config file. On some installations, skip-networking
is enabled by default and the sever won't listen for connections from other computers.
Also, it's possible the server will not forward any packets to 127.0.0.x, as that is reserved for localhost. To determine that, make sure basic networking is working between the two computers (ping, traceroute).
Spitting out a fixed "connection failed" error message is utterly useless for debugging purposes. Try this instead:
if (mysql_connect('127.0.0.3:3303', 'root', '12345')) {
...
} else {
die(mysql_error());
}
Have MySQL tell you EXACTLY what the problem is, instead of just saying there's a problem and flailing around in the dark.
精彩评论