Call Anytime 1-888-278-9780 or
Live Chat
Home > Knowledgebase > Getting Started: Connecting to a MySQL database using php

Question/Problem
Getting Started: Connecting to a MySQL database using php

Answer/Solution

To connect your web page to your MySQL database:

  1. Enable CGI
    1. To check if your CGI is enabled, go to /controlpanel/settings.bml
      If your CGI is enabled, you will see CGI Active.
      If CGI is not enabled, go to /controlpanel/powerpack/checkCGI.bml to enable it. 

  2. In your php script, include the following lines of code that specify the username, host, password, and database name so that any future changes would only have to be done once:

    $username = "username";
    $password = "password";
    $host="AcctUsername.fatcowmysql.com";
    $database="your_database"

    Where "username" is your database username, "AcctUsername" is your hosting account username, "password" is your database password, and "your_database" is the name of your database.

  3. To start a database connection, include the following line of code next:

    $conn = mysql_connect($host,$username,$password);

    Note that you need to name your connection. You will need this name in the next step.

  4. Then, select the specific database you wish to use by including this line of code:

    mysql_select_db($database, $conn);
You will now be connected to the database and can run MySQL operations on it via PHP. For more information, see PHP: MySQL Functions
Updated 08/28/14


How helpful did you find this article?

Click stars to rate the article:
star star star star star
Comments (optional):

Please login to view your tickets.

Live Chat