Home arrow ASP arrow Page 2 - Using MyODBC To Access Your MySQL Database Via ASP

Using MyODBC To Access Your MySQL Database Via ASP

MySQL is the most popular open source database system available today, and is currently installed on over two million servers worldwide. In this article Annette takes a look at using the free MyODBC driver to talk to a MySQL database from an ASP script.

Author Info:
By: Annette Tennison
Rating: 5 stars5 stars5 stars5 stars5 stars / 260
January 18, 2002
  1. · Using MyODBC To Access Your MySQL Database Via ASP
  2. · Installing MyODBC
  3. · Setting up a system DSN
  4. · Using a connection string
  5. · Querying our MySQL database
  6. · Conclusion

print this article

Using MyODBC To Access Your MySQL Database Via ASP - Installing MyODBC
(Page 2 of 6 )

If you've ever done any work with databases through ASP using ADO, then you've probably used an ODBC driver to connect to that database. Several ODBC drivers come pre-installed with Windows, and they allow us to connect-to and manipulate several different databases using one a consistent set of objects.

MyODBC is the Open Database Connectivity (ODBC) compliant driver that we can use to connect to a MySQL database. Here's how MySQL.com describes the MyODBC driver:

"MySQL provides support for ODBC by means of [the] MyODBC program. MyODBC is a 32-bit ODBC (2.50) level 0 (with level 1 and level 2 features) driver for connecting an ODBC-aware application to MySQL.

MyODBC works on Windows95, Windows98, NT, 2000, XP and on most Unix platforms. Very many people use MyODBC daily with Access, VBA, Excel, Word, Delphi, ASP, Cold Fusion and more."

MyODBC is a free download from MySQL.com and is a snap to stall. Let's take a look at how to install the MyODBC driver right now.

[Note] I'm assuming that you either already have MySQL installed either on your PC, or have the login details of a remote PC where MySQL is installed. Either way, make sure you have access to a MySQL server before continuing. If youíve never used MySQL, checkout Mitchell's article entitled "MySQL: Open-Source Power" here [End Note]
  1. Start by firing up your web browser and heading over to http://www.mysql.com. Take a look under the "Versions" tab on the right hand side of the page and click on MyODBC. At the time of writing, the current version on MyODBC was 2.50.39.
  2. Under the "MyODBC for Windows" section, click on the link that matches your operating system. In this article I'm focusing on Windows NT/2000, so click the NT/2000/XP link. This will take you to the mirrors page. Click on the link for the mirror that's closest to you and save the download to a folder on your hard drive (The download is a 1.45MB .zip file, so visit WinZip.com to download WinZip if you havenít got it already).
  3. Once complete, extract the zip file to a temporary directory and run the included setup.exe file. This will install the MyODBC driver. When the installation is completed, simply click on the close button to bypass the data sources configuration dialog. Click the OK button and you're done!
If the setup program reports any errors or behaves in a weird way, check out the MySQL documentation.

Now that we've got the MyODBC driver installed, let's setup a MySQL database so that we can take a look at the connect to a MySQL database.

Setting up our MySQL database

Before I discuss using DSN's and the connection string to connect to a MySQL database, let's create a new MySQL database.

Using the MySQL console application available on both Windows (c:\mysql\bin\mysql.exe) and Linux/Unix (/usr/local/mysql), enter the following code to create a new database and one new table, which we will use later to play around with some MySQL commands:

create database address;

use address;

create table contacts


contactId int auto_increment not null,

firstName varchar(50),

lastName varchar(50),

address1 varchar(100),

address2 varchar(100),

phone varchar(20),

primary key(contactId),

unique id(contactId)


I won't go into too much detail about the SQL above, but we've just created a new database named address, which contains one table named contacts.

Let's now look at how we can setup a system DSN to access our MySQL database through ASP.
blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials