Page 1 of 1

How PHP on webserver can access an external Mysql database?

PostPosted: 05. January 2007 05:40
by dinhaan
Hi all,

I've just studied to build a webserver using Xampp. My sites can be accessed from every PC within the LAN but outside PCs can not.
I have a default account on the LAN server, so I can post my site there then it can be browsed anywhere but my problem is the MySQL database can not be accessed or modified then (it is located in my own PC).
Can PHP program on the Webserver access my external MySQL database???
Pls give me some sample commands.

Thanks for help !!!

PostPosted: 05. January 2007 14:29
by Wiedmann
my problem is the MySQL database can not be accessed or modified

Why not?
--> error message

PostPosted: 05. January 2007 15:21
by dinhaan
Dear Wiedmann,
I know an external Mysql database can be accessed and modified but actually I dont know how to write the PHP program on the server :( .
Can you show me some example !!!

PostPosted: 05. January 2007 16:29
by Wiedmann
I dont know how to write the PHP program on the server

In PHP there is no difference in accessing a remote or a local database server (exept for the hostname).

Can you show me some example !!!

Just look at the MySQL examples in the PHP manual.

PostPosted: 06. January 2007 04:57
by dinhaan
This is the first time I work with PHP.
My sites are hosted on the webserver with the url http://my_school_webserver/~myaccount/
The mysql server database is located on my own PC (xxx.xxx.xx.xx).
I write a small task to access the sql database like this:
<?
mysql_connect('xxx.xxx.xx.xx:3306','my_user','my_password')
or die ("Unable to connect to database: ". mysql_error());
mysql_select_db('my_db')
or die ("Unable to select database");
?>

then I include this function to other PHP program that need to connect to the db.

When I access to the site, the error is:
"Can't not connect to MySQL server on 'xxx.xxx.xx.xx' (4) "
I also try the command without the port 3306, the error is the same.
Can you help me with this error !

PostPosted: 06. January 2007 12:08
by Wiedmann
"Can't not connect to MySQL server on 'xxx.xxx.xx.xx' (4) "

There is no MySQL-Server running at the ip 'xxx.xxx.xx.xx'. (or can't be accessed, e.g. because of a firewall).

PostPosted: 07. January 2007 15:51
by dinhaan
Hi Wiedmann,
The MySQL Server is running (it is included with XAMPP1.5.5). I turned off the firewall, then another error occurs: "Host 'my_school_webserver' is not allowed to connect to this MySQL server".
How could I set the permission so that the Webserver can connect to the MySQL server :cry: .
Thanks for help.

PostPosted: 07. January 2007 16:15
by Wiedmann
How could I set the permission so that the Webserver can connect to the MySQL server

Your user (eg. "my_user") must have "%" as host value and not "localhost".

Change this with phpMyAdmin --> "privileges".

PostPosted: 07. January 2007 17:05
by dinhaan
You spent much time for helping me, Wiedmann.
It's working now.
Thank you so much !!!