Asp connects to the mysql database through the system DSN

Source: Internet
Author: User
Tags dsn mysql host

System: win2003
Step 1: configure the ODBC Data Source

Create a DSN In the ODBC data source. The specific method is:

1. Open the ODBD data source in the control panel;

2. Select "system DSN" and add a new DSN driver;

3. select mysql odbc 3.51 driver. A dialog box is displayed for you to enter MySQL:
(1) Windows DSN name: name of the DSN to be created, that is, the name of the database;
(2) MySQL Host (name or ip): The name or ip address of the MySQL server. Generally, enter LocalHost;
(3) MySQL database name: the name of the database to be used.

4. Create a database in the MySQL management program.
(1) user: the user name used to connect to the database. Enter root Super User;
(2) password: password used to connect to the database. Optional;
(3) Port (if not 3306): MySQL Port on the server. Enter 3306 by default;
(4) SQL command on connect: use SQL commands to connect to the database. Optional.
After entering all the information, press OK to save.

Step 2: Compile the database link file
For example, there is a database discut, the data table cdb_posts, the field: Name subject (the program is as follows :)

<%
Dim driverName, chs
DriverName = "Driver = {mysql odbc 3.51 driver}; server = localhost; database = discuz; uid = root; pwd = ;"
Set conn = server. createobject ("adodb. connection ")
Conn. open driverName

'Execute the following sentence before querying. This sentence is the key to solving the problem of reading database garbled characters.
Set chs = conn. Execute ("set names 'gb2312 '")

'Query a table
Set rs = conn. Execute ("Select * FROM cdb_posts ")
If Not Rs. Eof Then
Do While Not rs. EOF
If Rs. Eof Or Rs. Bof Then Exit Do
Response. Write rs ("subject") & "<br>"
Rs. MoveNext
Loop
End If
Rs. Close
Set Rs = Nothing
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.