100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > C语言访问MySQL数据库办法【MySQL】

C语言访问MySQL数据库办法【MySQL】

时间:2023-11-21 00:25:31

相关推荐

C语言访问MySQL数据库办法【MySQL】

数据库|mysql教程

语言,数据库,方法

数据库-mysql教程

1、添加头文件路径(MySQL安装路径中的include路径)

斗牛app源码,vscode如何运行一个项目,ubuntu安装pr,tomcat系统运行日志,东京爬虫馆,PHP空间购买分享,沈阳创新抖音seo优化程序lzw

2、添加库文件(直接从MySQL安装路径中copy libmysql.lib即可)

网络建站源码,vscode复制图片,查看ubuntu密码,远程安装tomcat,sqlite 导微信数据,爬虫文章太多了怎么停止下载,php 判断是否是ip,seo专业推广收录,淘宝客采集网站有哪些,网页制作音乐播放器代码,android菜单模板demolzw

3、编程操作数据库

手机装机联盟源码,vscode提示背景色补全,博通ubuntu,tomcat域名发布web,菜地杀爬虫,国内php高手,仓山区正规seo服务电话lzw

代码

// AccessToMySQL.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #pragma comment(lib,"libmysql.lib")MYSQL mysql;MYSQL_RES* result;MYSQL_ROW row;int main(void){//init the mysql parametermysql_init(&mysql);//connect the database if(!mysql_real_connect(&mysql,"127.0.0.1","root","111","mytest",3306,NULL,0)){printf(mysql_error(&mysql));printf("\nCannot access to the database!!!\n");system("pause");exit(-1);}//construct the query SQL statementschar* sql="select * from student where name=\";char dest[100]={""};strcat(dest,sql);printf("Please enter the student name:");char name[10]={""};gets(name);strcat(dest,name);strcat(dest,"\");//excute the SQL statementsif(mysql_query(&mysql,dest)){printf("Cannot access the database with excuting \"%s\".",dest);system("pause");exit(-1);}//deal with the resultresult=mysql_store_result(&mysql);if(mysql_num_rows(result)){while((row=mysql_fetch_row(result))){printf("%s\t%s\t%s\n",row[0],row[1],row[2]);}}//release the resourcemysql_free_result(result);mysql_close(&mysql);system("pause");return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。