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 2 of 2
  1. #1
    New Coder
    Join Date
    May 2009
    Location
    philippines
    Posts
    50
    Thanks
    6
    Thanked 1 Time in 1 Post

    how to connect to MySQL Database

    i've reading and practicing a little with PHP and MySQL. i've set-up a local environment for the exercises. i've been fairly often using the code :
    PHP Code:
    $connection mysql_connect('localhost''root''pass') or die('unable to connect'); 
    my problem is that, this code works fine in my local environment, but i don't know how the above code should be written to be able to connect to my database in the real world of the web? i know the 'root' should be replaced with the username while 'pass' should be replaced with the actual password of the username, but i'm wondering what i should replace 'localhost' with if i were to access the MySQL database in the on-line server? should i replace 'localhost' with 'http://some_domain_name.com/the_MySQL_folder' ?

    thanks..

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,043
    Thanks
    2
    Thanked 316 Times in 308 Posts
    It can be 'localhost' if that is what has been configured, or it can be the DNS name of the mysql server, or it can be the IP address of the mysql server. Which one of these depends on how the web host has setup the web server/mysql server. The best way to determine which one would be to consult the web host's documentation.
    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.

  • Users who have thanked CFMaBiSmAd for this post:

    sim_pack (06-16-2009)


  •  

    Posting Permissions

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