Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of connecting mysql Database with vc

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article is about VC connection to MySQL database. Xiao Bian thinks it is quite practical, so share it for everyone to make a reference. Let's follow the editor and have a look.

vc connection mysql database method: first open VC6; then add the local installation MySQL include directory path in the middle list box; then select "Library files" and add MySQL Lib directory path; finally programming test can be.

I. MySQL installation

Mysql installation can be downloaded from the official website... The latest version is version 5.7.

II. Settings of VC6.0

(1) Open the Options option under the Tools menu in the toolbar of VC6. Select "Includes" in the "Show directories for:" drop-down list on the right side of the Directories tab, and then add the include directory path of your local MySQL installation in the middle list box. As shown in the figure:

(2) Select "Library files" in the "Show directories for:" drop-down list mentioned above, and then add the Lib directory path of your local MySQL installation. As shown in the figure:

** Note here: Careful people will find that my directory is different from the one in the previous figure because of this error: libmysql.lib : fatal error LNK1113: invalid machine Invalid server

This is because vc development is a 32-bit program, and mysql database is 64-bit caused, you use 32-bit program to operate 64-bit database will certainly make mistakes, I will explain in detail how to solve in the next blog post.

(3) Add "libmysql.lib" to "Project settings->Link:Object/library modules".

(5) It is recommended to copy "libmySQL.lib, libmySQL.dll" to the directory of your project.

These two files are located in the D:\Mysql\lib directory.

III. Programming implementation

1. A simple Mini programs to see if they can connect successfully...

#include #include #include int main(){ MYSQL mysql; mysql_init(&mysql); //initialize mysql structure if(! mysql_real_connect(&mysql,"localhost","myuser","123456","student_db",3306,NULL,0)) printf("\nError connecting to database!\n n"); else printf("\nDatabase connection successful!\n n"); mysql_close(&mysql); //release database return 0;}

mysql_real_connect(&mysql,"localhost","myuser","123456","student_db",3306,NULL,0)//myuser is my username,"123456" is my password,"student_db" is my database, 3306 is my port number

2. Mini programs for query implementation

// test.cpp : Defines the entry point for the console application.//# include #include #include "StdAfx.h"#include #include #include #include using namespace std; //comment out those that don't need stepping//#define STEPBYSTEP void pause(){ #ifdef STEPBYSTEP system("pause"); #endif } void writeToFile(const char *s) { FILE *fp=fopen("info.txt","rw"); fprintf(fp,s); fclose(fp); } /* int main(){ MYSQL mysql; mysql_init(&mysql); //initialize mysql structure if(! mysql_real_connect(&mysql,"localhost","myuser","123456","student_db",3306,NULL,0)) printf("\nError connecting to database!\n n"); else printf("\nDatabase connection successful!\n n"); mysql_close(&mysql); //release database return 0;}*/int main(int argc, char* argv[]){ cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report