Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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:

    PHP Code:
    <?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?

  • #2
    New Coder
    Join Date
    Aug 2007
    Location
    Wagga, Australia
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post
    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
    Code:
    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
    Last edited by usik; 08-24-2007 at 01:12 PM.

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,129
    Thanks
    2
    Thanked 328 Times in 320 Posts
    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.)
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    If you run
    PHP Code:
    phpinfo(); 
    It will tell you if a) PHP is working, and B) The MySQL extension is enabled.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •