Home  >  Article  >  Database  >  C++对Mysql数据库的访问查询(基于Mysql5.0的API,vs2010中操作

C++对Mysql数据库的访问查询(基于Mysql5.0的API,vs2010中操作

WBOY
WBOYOriginal
2016-06-07 15:34:321188browse

右击项目名称-属性,配置引用Mysql数据库的库目录,见图: 添加附加包目录为C:\Program Files\MySQL\MySQL Server 5.0\include 拷贝libmySQL.dll(C:\Program Files\MySQL\MySQL Server 5.0\bin)和libmysql.lib(C:\Program Files\MySQL\MySQL Server 5.0\lib

 

右击项目名称->属性,配置引用Mysql数据库的库目录,见图:

C++对Mysql数据库的访问查询(基于Mysql5.0的API,vs2010中操作

添加附加包目录为C:\Program Files\MySQL\MySQL Server 5.0\include

C++对Mysql数据库的访问查询(基于Mysql5.0的API,vs2010中操作

拷贝libmySQL.dll(C:\Program Files\MySQL\MySQL Server 5.0\bin)和libmysql.lib(C:\Program Files\MySQL\MySQL Server 5.0\lib\opt)到运行目录下,如调试时放在Debug下

然后代码如下

#include "windows.h"
#include "winsock.h"
#include "stdio.h"
#include "mysql.h"
#pragma comment(lib,"libmySQL.lib")
#include <iostream>
using namespace std;
int main()
{

	char dbuser[30]="root";
	char dbpasswd[30]="password";
	char dbip[30]="localhost";
	char dbname[50]="temperature";
	MYSQL *con=mysql_init((MYSQL *)0);
	
	if (con!=NULL&&mysql_real_connect(con,dbip,dbuser,dbpasswd,dbname,3306,NULL,0))
	{
		printf("SUCCESSFULLY.");
		mysql_query(con,"select * from temperature");
		MYSQL_RES *result=mysql_store_result(con);
		unsigned int fieldcount=mysql_num_fields(result);
		coutname
<p><br>
 </p>


</iostream>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn