...

View Full Version : Connecting to External Database using Apache2



gc40
08-24-2007, 08: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?

usik
08-24-2007, 12:08 PM
Have you checked the mysql server settings to see if it accepts remote connections? you can edit the mysql config file and set the bind address to your homes computer or update the database and set a specific ip address to be allowed access 2 it


mysql> update db set Host='202.54.10.20' where Db='webdb';


also check to make sure you have got the mysql extension for php enabled in the php config file

CFMaBiSmAd
08-24-2007, 03:28 PM
If you are not getting any output, not even the output contained in your or die(...) statement, that would indicate that php is probably not working or the mysql extension is not enabled. Have you tried a simple script that just echo's something?

If php is working, then the mysql extension is probably not enabled. Either check your web server log for errors and/or turn on full php error reporting (both display_errors to on and error_reporting to E_ALL) in php.ini or a .htaccess file. Turning on full php error reporting will save you a tremendous amount of time when developing code.

If php is working and the mysql extension is enabled, adding mysql_error() in your or die(...) statement, will give you more information as to why the connection is not working.

If everything on your local computer is setup and working, then either the remote mysql server is not setup to accept any remote connections, or it needs to be setup to allow a specific remote connection from your computer (per usik's post above.)

Inigoesdr
08-24-2007, 04:11 PM
If you run
phpinfo(); It will tell you if a) PHP is working, and B) The MySQL extension is enabled.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum