database connection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

database connection

Post by gurjit »

hi all,

i'm trying to connect to a database on server 2 and my website is on server 1.

lets say
server 2 ip is 163.1.209.3
server 1 ip is 189.4.689.7

in my db connections file on server 1 i do this

Code: Select all

<?php
$hostname = "163.1.209.3";
$database = "mydb";
$username = "us";
$password = "pa";
$my_conn = mysql_connect($hostname, $username, $password) or die(mysql_error());

mysql_select_db($database,$my_conn);

?>
what am i doing wrong?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Does the server allow remote connections?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ya, your code is fine. Check if the server allows remote connections - like ~redmonkey said. Also, make sure the user you are using can connect to that specific database from that specific IP. I know my servers only allow connections from localhost and explicitely stated IP's, never '%'.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply