How PHP on webserver can access an external Mysql database?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

How PHP on webserver can access an external Mysql database?

Postby dinhaan » 05. January 2007 05:40

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 !!!
dinhaan
 
Posts: 9
Joined: 03. January 2007 16:16

Postby Wiedmann » 05. January 2007 14:29

my problem is the MySQL database can not be accessed or modified

Why not?
--> error message
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby dinhaan » 05. January 2007 15:21

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 !!!
dinhaan
 
Posts: 9
Joined: 03. January 2007 16:16

Postby Wiedmann » 05. January 2007 16:29

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.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby dinhaan » 06. January 2007 04:57

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 !
dinhaan
 
Posts: 9
Joined: 03. January 2007 16:16

Postby Wiedmann » 06. January 2007 12:08

"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).
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby dinhaan » 07. January 2007 15:51

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.
dinhaan
 
Posts: 9
Joined: 03. January 2007 16:16

Postby Wiedmann » 07. January 2007 16:15

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".
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby dinhaan » 07. January 2007 17:05

You spent much time for helping me, Wiedmann.
It's working now.
Thank you so much !!!
dinhaan
 
Posts: 9
Joined: 03. January 2007 16:16


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 114 guests