How do I use a connection string to connect to a MySQL database?

The following article explains how to use a connection string to connect to a MySQL database from a Windows server. The syntax of the connection string will vary based on the programming language you are using. Below are sample connection strings for ColdFusion, Perl and ASP. The code snippets can be added directly to your code.

In the following examples, please substitute your information where the following data is referenced:

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;"
%>

Additional Support Topics

Search Support Articles

SAS 70, PCI, BBB

© Hosting.com 2009
Contact Us
Terms of Service
Privacy Policy
AUP

Hosting.com is an Equal Employment Opportunity/Affirmative Action Employer (EEO/AA).