How do I connect to my MySQL database?

How do I connect to my MySQL database?

This answer explains how you can connect to your MySQL database using simple PHP and ASP scripts.

This article applies to Shared Hosting accounts.

 

The database itself does not exist as a file that you can upload or download using FTP. You can connect to the database in two ways: using ODBC compliant software and via PHP version 3 or later. We also support CGI and PERL DB modules to allow you to connect.

PHP- For direct integration of the database into your web pages for dynamic updates we provide the HTML-embedded scripting language PHP.

The basic command that you need to use in your PHP script is:

  $mysql_link = mysql_connect("mysql01", "USERNAME", "PASSWORD")
 
 

If you require further details of commands needed to handle the database once you’re connected, please visit www.php.net

ASP You will need to use a DSNless connection which can be achieved by using code with the following VBscript:

rsEvents = Server.CreateObject("ADODB.Recordset")
rsEvents.ActiveConnection = "Driver={MySQL};
DATABASE=databasename;UID=username; PASSWORD=password;" 
 

For example:

rsEvents = Server.CreateObject("ADODB.Recordset")
rsEvents.ActiveConnection = "Driver={MySQL}; DATABASE=foodb;UID=foo; PASSWORD=bar;"