Using MySQL with ASP
(Page 1 of 4 )
In this article I will show you how to use MySQL with ASP. It is often said that open source and commercial software are not the best of friends. But in this case you will see that there are exceptions.
The requirements
First you need the following tools:
MySQL database server, available from http://www.mysql.com/ .
ODBC 3.51 (also available from link above) - This is the driver that will enable you to connect to MySQL from within ASP.
Any MySQL Client (for example, Mysqlfront available from http://www.anse.de/mysqlfront/).
An IIS server (I'm using IIS5) or a web server that is capable of rendering ASP pages.
Now install all of them and restart your computer to make sure that everything is properly set up. After you have finished setting up the MySQL database server and the client, create a new database, add the following SQL and run it.
# Database : `userinfo`
#
# --------------------------------------------------------
#
# Table structure for table `guests`
#
CREATE TABLE `guests` (
`gid` int(4) NOT NULL auto_increment,
`name` varchar(20) NOT NULL,
`comment` text NOT NULL,
`dateAdd` date NOT NULL,
PRIMARY KEY (`gid`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
#
# Dumping data for table `guests`
#
INSERT INTO `guests` VALUES (1, 'Dennis Brown', 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', '2008-07-31');
INSERT INTO `guests` VALUES (2, 'Xuros', 'sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', '2008-07-31');
The SQL above simply creates a table called guests, from which you will be retrieving data shortly. Also, please write down the user name and password that you create during the installation process; you will need it in the next section.
The next step is to set up a system DNS. Open up the control panel on your computer and then go to Administrative Tools->Data Sources (ODBC). A screen that looks like this should come up:
Click on the System DSN tab and then add the button. You should now see a window that looks something like this:
Scroll down, select MySQL ODBC driver and click "Finish." You should now come to a window that looks something like this:
What you need to fill in is the user name and password. If you have installed MySQL 5, your username will almost certainly be "root." As for the password, you will be the only one who knows what it is. Once your password and user name is filled in, you will be able to view a list of databases from the drop-down box. Select the userinfo database from there. Click OK until all the dialog boxes are closed.
Next: Connecting with ASP >>
More ASP Articles
More By David Web