当前位置:网站首页>Linking MySQL database with visual studio2015 under win10
Linking MySQL database with visual studio2015 under win10
2022-06-25 23:49:00 【smileapples】
Introduction to the environment
operating system :win10
mysql Database version (64 position ):
visual studio:2015 pro 
Installation steps
0、 install mysql database ( Default installation path )
1、 To connect to the database, first configure the environment
First the C:\Program Files\MySQL\MySQL Server 8.0\lib Under the libmysql.dll Copied to the C:\Windows\System32 in 
2、 modify win32 consoleapplication by 64 position

If it is not modified to x64, The following errors will be reported :
3、 Item attribute ->VC+±> Include directory add mysql\include route , Used to reference header files

4、 Item attribute -> The linker -> routine -> Additional Library Directory add to mysql\lib route

5、 Item attribute -> The linker -> Input -> Additional dependency add to libmysql.lib Name is enough ( Add only static libraries )

Test code :
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include<mysql.h>
#pragma comment(lib,"libmysql")
int main()
{
// initialization
MYSQL * mysql = mysql_init(NULL);
if (mysql == NULL)
{
printf(" initialization failed %s", mysql_error(mysql));
return EXIT_FAILURE;
}
// Change character set to utf-8
system("chcp 65001");
mysql_set_character_set(mysql, "utf8");
MYSQL * contMysql = mysql_real_connect(mysql,
"127.0.0.1",// Address
"root",// account number
"xxxxx",// password
"testdb",// database
3306,// port
NULL,
0
);
if (contMysql == NULL)
{
printf(" link failure %s", mysql_error(mysql));
return EXIT_FAILURE;
}
std::cout << "Connect success\n";
// Create database
int ret = mysql_query(contMysql, "create database If Not Exists myNewDatabase");
if (ret)
{
printf(" Failed to create database %s", mysql_error(mysql));
return EXIT_FAILURE;
}
// Create table
ret = mysql_query(contMysql, "create table If Not Exists myNewDatabase.T_STUDENT (sid varchar(50),sname varchar(50))");
if (ret){
printf(" Failed to create table %s", mysql_error(mysql));
return EXIT_FAILURE;
}
// Add data
ret = mysql_query(contMysql, "create table If Not Exists myNewDatabase.T_STUDENT (sid varchar(50),sname varchar(50))");
if (ret){
printf(" Failed to create table %s", mysql_error(mysql));
return EXIT_FAILURE;
}
// Insert
ret = mysql_query(contMysql, "insert into myNewDatabase.T_STUDENT values('s002',' Hello ')");
if (ret){
printf(" Insert the failure %s", mysql_error(mysql));
return EXIT_FAILURE;
}
// Inquire about
ret = mysql_query(contMysql, "select * from myNewDatabase.T_STUDENT ");
if (ret){
printf("Query faliure %s\n", mysql_error(mysql));
return EXIT_FAILURE;
}
else {
// Save the results of the query
MYSQL_RES* res = mysql_store_result(contMysql);
MYSQL_FIELD* field;
// Query which fields are returned here sid sname
while ((field = mysql_fetch_field(res)))
{
printf(" %s\t", field->name);
}
unsigned int num_fields = mysql_num_fields(res);
printf("\r\n");
MYSQL_ROW row;
while (row = mysql_fetch_row(res))
{
for (size_t i = 0; i < num_fields; i++)
{
printf("%s ", row[i]);
}
printf("\r\n");
}
mysql_free_result(res);
}
mysql_close(contMysql);
return 0;
}
test result

边栏推荐
猜你喜欢
![Classic image segmentation network: UNET supports libtorch deployment reasoning [with code]](/img/3a/fb3bfe673db5123e3124404f3905c0.png)
Classic image segmentation network: UNET supports libtorch deployment reasoning [with code]

期末复习【机器学习】

UE4 learning record 2 adding skeleton, skin and motion animation to characters

final和static

Analyse des cinq causes profondes de l'échec du développement de produits

Gradle的环境安装与配置

先序线索二叉树

使用百度地图API在地图中设置一个覆盖物(InfoWindow),可自定义窗口内容

18亿像素火星全景超高清NASA放出,非常震撼

OpenResty篇01-入门简介和安装配置
随机推荐
mysql
213.打家劫舍 II
7.常用指令(下)v-on,v-bind,v-model的常见操作
STL教程5-STL基本概念及String和vector使用
利用swiper实现轮播图
C ++ 引用与指针总结
达梦数据库修改字段信息采坑记
Database - mongodb
Analysis on resource leakage /goroutine leakage / memory leakage /cpu full in go
说说单例模式!
Uniapp -- the use of document collation and push of unipush
idea Kotlin版本升级
为什么Integer的比较最好使用equals
解析产品开发失败的5个根本原因
The simplest screen recording to GIF gadget in history, licecap, can be tried if the requirements are not high
Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
聊聊swoole或者php cli 进程如何热重启
php中使用Makefile编译protobuf协议文件
Object类常用方法
Solve 'tuple' object has no attribute 'lower‘