Click to See Complete Forum and Search --> : Connecting to External Database using Apache2


gc40
08-24-2007, 02:27 AM
Greetings All,
I have been for the longest while testing my .php website files by uploading them to my server first and going to the URL. However, this is the biggest waste of time ever.

I finally decided to setup Apache2 Server and php 5 on my system. I also setup a mysql database. However, when i try to connect to an external database located on my server to test my application, I get no connection. I tested my connection with a script like this:


<?php
$username = "pee_wee";
$password = "let_me_in";
$hostname = "mysql.mywebsite.com";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
// you're going to do lots more here soon
mysql_close($dbh);
?>


Of course I enter the right connection info. I then take this same test connection file, upload it to my server and I get the echo 'Connected to MySQL'. When i test it on my local machine, I don't get any errors, or outputs. Does anyone know why this may be happening? I am not behind any firewalls, or anything of that nature. I think its a problem with how I setup apache2 or php or something. Does anyone know how I can get a mysql database working on my local system prefferably with phpmyadmin?

stephan.gerlach
08-24-2007, 03:00 AM
quite often hosting companies don't allow database connections from servers outside their network. Check with your host and see if they actually allow it.

gc40
08-24-2007, 03:03 AM
They do allow it. Any other reasons?

stephan.gerlach
08-24-2007, 03:05 AM
do you put a http:// in front of the server url? If not try that

gc40
08-24-2007, 03:07 AM
For the mysql host?!! http//? Are you sure?! :S

stephan.gerlach
08-24-2007, 03:10 AM
actually no. try this one instead


$hostname = "mysql.mywebsite.com:3307";

gc40
08-24-2007, 03:59 AM
No luck with port 3307...

<?php
$username = "user";
$password = "pass";
$hostname = "mysql.domain.com:3307";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
// you're going to do lots more here soon
mysql_close($dbh);
?>

I am not getting an either echo outputs! When I test it on my server, I either get Connected to MySQL or Unable to connect to MySQL (depending if settings are right or wrong).