How do I make a connection to a MySQL database using ASP, Perl, or ColdFusion?
The following article explains how to make a connection to a MySQL database using ASP, Perl or ColdFusion. The method used will be a DSN-less connection, which requires you to specify the servername, database, username and password. Currently we do not support DSN connections to MySQL databases using ASP.
Note: The MySQL database is stored on a Linux server, which means your SQL statements need to be case sensitive. For example, "SELECT * FROM Table" and "SELECT * FROM table" will be interpreted as two different SQL statements.
In the following examples, please substitute your information where the following data is referenced:
- server: 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 database name provided for your database
ColdFusion
<CFQUERY Name="test" DATASOURCE="<DSN>" USERNAME="<username>"
PASSWORD="<password>">
</CFQUERY>
Perl
#!/usr/bin/perl
use DBI;
$db = DBI->connect("dbi:mysql:<database>:<servername>","<username>","<password>")
or die("Couldn't connect");
$db->disconnect;
ASP
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=<server>; PORT=3306; DATABASE=<database>; USER=<username>; PASSWORD=<password>; OPTION=3;"
%>