I am developing a web page which retrieve data from a seperate mysql server
on the same network
musql_connect('192.16.1.2:3306', 'root', '123');

but ana error shows

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '192.16.1.2' (13) in /var/www/html/index.php on line 3

the 2 servers are on 2 different virtual network (I am using centos on virtual box)

I have set the webserver(apache) on 192.16.1.1
and the mysql on 192.16.1.2

when I tried locally it had worked!

please help

Recommended Answers

All 8 Replies

I am developing a web page which retrieve data from a seperate mysql server
on the same network
musql_connect('192.16.1.2:3306', 'root', '123');

but ana error shows

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '192.16.1.2' (13) in /var/www/html/index.php on line 3

the 2 servers are on 2 different virtual network (I am using centos on virtual box)

I have set the webserver(apache) on 192.16.1.1
and the mysql on 192.16.1.2

when I tried locally it had worked!

please help

This is your problem, not PHP or MySQL. Log into your webserver VM and try to ping your VM running MySQL. You probably can't.

Figure out your VM/network configuration and you php/mysql issue will be fixed.

I have successully pinged both VMs

but the problem still exists!

Just noticed a typo - if this code was copy/pasted it's probably your problem:

musql_connect('192.16.1.2:3306', 'root', '123');

^^ should be mysql_connect...

Just thought I'd mention it ;)

Thank you, but it is bot copy paste
I have tried to do it locally and it worked,
I have checked the spelling and it is write (mysql_connect....)

I have successully pinged both VMs

Did you ping both VMs from you local machine? Try pinging you MySQL vm from you webserver vm. VM To VM. 192.16.1.1 to 192.16.1.2 and preferably on the required port of 3306

From your error, it's the connection specifically that's an issue and is a definite difference between running it locally and the VM.

yes I did.
But I think I should configure /etc/my.cnf file and enable networking
does anyone Know how?
thank you

skipnetworking is commented!
but haven't worked :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.