/    Sign up×
Community /Pin to ProfileBookmark

Connecting to External Database using Apache2

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:

[code=php]
<?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);
?>
[/code]

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?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachAug 24.2007 — 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.
Copy linkTweet thisAlerts:
@gc40authorAug 24.2007 — They do allow it. Any other reasons?
Copy linkTweet thisAlerts:
@stephan_gerlachAug 24.2007 — do you put a http:// in front of the server url? If not try that
Copy linkTweet thisAlerts:
@gc40authorAug 24.2007 — For the mysql host?!! http//? Are you sure?! :S
Copy linkTweet thisAlerts:
@stephan_gerlachAug 24.2007 — actually no. try this one instead

[code=php]
$hostname = "mysql.mywebsite.com:3307";
[/code]
Copy linkTweet thisAlerts:
@gc40authorAug 24.2007 — No luck with port 3307...

[code=php]<?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);
?>[/code]


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).
×

Success!

Help @gc40 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...