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.
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]
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.
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).
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;
create table contacts
contactId int auto_increment not null,
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.