C语言连接mysql的问题,不知道有没有需要的函数,求大师

jdwq33 2013-07-18 07:32:23
用C语言连接mysql:
例如我现在又两个表,
table one{id_key int(20), name varchar(20)};
table two{id_key int(20), name varchar(20), sex char(1)};
大概就这些了,这边就举例,我通过one表和two表的id_key是对应的,然后我想通过这个id_key
去访问two里面的内容,但是我mysql里面没有API函数,他只有mysql_fetch_row()函数,
我想通过id_key就能打印出name的信息(如果里面的字段有很多我只需要name),其他的信息我不需要。
因为mysql_fetch_row()函数知识索引,但是如果这个表更新了那样就不行了。
今天弄了一天都没弄出来,希望大师们帮帮忙啊!拜谢!!!
...全文
181 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
兆帅 2013-07-26
  • 打赏
  • 举报
回复
引用 4 楼 hzhxxx 的回复:
MYSQL C API 访问程序(更新升级版本) . http://blog.csdn.net/hzhxxx/article/details/6100752
++
Kaile 2013-07-24
  • 打赏
  • 举报
回复
这个文章不错, C++操作mysql数据库文章资料汇总 下面是文章中的例子: #include "stdafx.h" #include <stdio.h> #include <winsock.h> #include <mysql.h> #include <windows.h> #pragma comment(lib, "libmysql.lib") int main(int argc, char* argv[]) ...{ unsigned short Port = 3306; char *IPAddress = "192.168.31.56"; char *UserName = "root"; char *Password = ""; char *DBName = "SAS_1_2_0"; printf("Start... "); MYSQL *ssock; //char execsql[500]; ssock = (MYSQL *)malloc(sizeof(MYSQL)); //在某些版本中,不需要该初始化工作,可观看mysql.H以及readme mysql_init(ssock); if(ssock == NULL) ...{ printf("EROR: MySQL ssock init error. "); return FALSE; } //连接指定数据库 ssock = mysql_real_connect(ssock, IPAddress, UserName, Password, NULL, Port, NULL, 0); if(!ssock) ...{ printf("conn fail... "); //memcpy(eee, mysql_error(ssock), 20); //fprintf(stderr, "Failed to connect to database: Error: %s ", mysql_error(ssock)); //printf("%c ", eee); unsigned int mtint = mysql_errno(ssock); //printf("%d "); return FALSE; } if(mysql_select_db(ssock, DBName) != 0) ...{ printf("select db error. "); return FALSE; } printf("version=%d ", mysql_get_server_version(ssock)); //exec my execsql string //sprintf(execsql,"create table girls (name char(10),age int)"); //mysql_real_query(ssock,execsql,strlen(execsql)); mysql_close(ssock); printf("End... "); return TRUE; }
jdwq33 2013-07-24
  • 打赏
  • 举报
回复
引用 2 楼 lgbxyz 的回复:
去数据库专区
恩 谢谢
hzhxxx 2013-07-24
  • 打赏
  • 举报
回复
MYSQL C API 访问程序(更新升级版本) . http://blog.csdn.net/hzhxxx/article/details/6100752
LubinLew 2013-07-23
  • 打赏
  • 举报
回复
去数据库专区
jdwq333 2013-07-23
  • 打赏
  • 举报
回复
怎么没有人回答啊,真是悲催啊!

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧