Connect to the MySQL database using vc6.0

Source: Internet
Author: User
Tags mysql query

MySQL: 5.5.

System: winodws XP

1. Set vc6.0

Reference: http://blog.163.com/aoxiangtiankong@yeah/blog/static/84112026200951051417721/

(1) Open the options Option Under the Tools menu in the vc6.0 toolbar, and select "includefiles" in the "show directories for:" drop-down list on the right of the directories tab ", then add the include directory path for local MySQL installation to the list box in the middle. (My files are D: \ Program Files \ mysql \ MySQL Server 5.0 \ include ).

(2) Select "library files" in the "show directories for:" drop-down list mentioned above, and then add the lib directory path for local MySQL installation. The lib directory contains two directories: Debug and OPT. We recommend that you select debug. (My files are D: \ Program Files \ mysql \ MySQL Server 5.0 \ Lib \ Debug ).

(3) Add "libmysql. lib" in "Project Settings-> link: Object/library modules ".

(4) we recommend that you copy "libmysql. lib and libmysql. dll" to the directory of your project.

Ii. VC Programming

Reference: http://blog.csdn.net/jiankangshiye/article/details/6068523

1. Create a Project Test

2. Set vc6.0

3. Create stdafx. h and add the following code:

# Include "Winsock. H" // put this line before # include "mysql. H" if a compilation error occurs.
# Include "mysql. H"
# Pragma comment (Lib, "libmysql. lib") // if it has been added to the additional dependency, do not add it.

4. Test .. CPP, add the following code

# Include "stdafx. H"
# Include "stdio. H"
# Include <string. h>
Struct conn_info
{
Char * Host;
Char * user;
Char * password;
Char * dB;
};

MySQL * mysql_conn_setup (conn_info con)
{
MySQL * MySQL = mysql_init (null );
If (! Mysql_real_connect (MySQL, Con. Host, Con. User, Con. Password, Con. DB, 3306, null, 0 ))
{
Printf ("conection error: % s/n", mysql_error (MySQL ));
Exit (1 );
}
Return MySQL;
}

Mysql_res * mysql_conn_sqlquery (MySQL * MySQL, char * SQL _query)
{
If (mysql_query (MySQL, SQL _query ))
{
Printf ("MySQL query error: % s/n", mysql_error (MySQL ));
Exit (1 );
}
Return mysql_use_result (MySQL );
}
Void main ()
{
MySQL * conn;
Mysql_res * res;
Mysql_row row;
Char SQL _query [100];
Memset (SQL _query, '\ 0', 100 );
Sprintf (SQL _query, "show tables ");
Struct conn_info Info;
Info. Host = "localhost ";
Info. User = "root ";
Info. Password = "1 ";
Info. DB = "MySQL ";
Conn = mysql_conn_setup (Info );
Res = mysql_conn_sqlquery (Conn, SQL _query );
Printf ("All MySQL tables: \ n ");
While (ROW = mysql_fetch_row (RES ))! = NULL)
{
Printf ("% s \ n", row [0]);
}

Mysql_free_result (RES );

Mysql_close (conn );
}

 

5. debug and compile OK

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.