How do I use PHP to access my MySQL database? (2024)

How do I use PHP to access my MySQL database?

Please note: This support article is a guide for our Linux users only.
The following article explains how to connect to a MySQL database using PHP. A MySQL database can be accessed on our servers using all of the programming languages available on the server. Unlike Perl, PHP contains native MySQL connection support, so it is not necessary to include a module.

In order to access your MySQL database with the PHP, please follow these steps:

  1. Log into your Linux web server via Secure Shell.
  2. Type the following connection string to connect to your database:

    <?php
    $link = mysql_connect('host', 'username', 'password') or die('Could not connect: ' . mysql_error());
    mysql_select_db('database') or die('Could not select database');
    ?>

    • host: enter the MySQL server that you are assigned to, for example, mysql4.safesecureweb.com
    • username: enter the username provided for your database
    • password: enter the password provided for your database
    • database: enter the name of the MySQL database
How do I use PHP to access my MySQL database? (2024)
Top Articles
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 5943

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.