偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

用c語(yǔ)言正確讀取MySQL數(shù)據(jù)庫(kù)實(shí)戰(zhàn)演示

數(shù)據(jù)庫(kù) MySQL
此文章主要描述的用c語(yǔ)言正確讀取MySQL數(shù)據(jù)庫(kù)的實(shí)際操作步驟,以下就是文章的詳細(xì)內(nèi)容講解,希望會(huì)給你帶來(lái)一些幫助在此方面。

以下的文章主要向大家描述的是用c語(yǔ)言正確讀取MySQL數(shù)據(jù)庫(kù)的實(shí)際操作流程,如果你對(duì)用c語(yǔ)言正確讀取MySQL數(shù)據(jù)庫(kù)的正確操作流程感興趣的話,那么以下的文章就會(huì)滿足你的好奇之心了。

最近一段時(shí)間我們學(xué)習(xí)了linux操作系統(tǒng)下的C開發(fā),呵呵,寫了一個(gè)測(cè)試程序,作用是讀取MySQL的數(shù)據(jù),然后顯示出來(lái)。經(jīng)測(cè)試成功…

  1. #include <stdio.h> 
  2. #include <stdlib.h> 
  3. #include <MySQL.h> 
  4. #define DB_SERVER ""  
  5. #define DB_NAME "test"  
  6. #define DB_USER "root"  
  7. #define DB_PWD ""  
  8. static MySQL *db_handel,MySQL;  
  9. static MySQL_ROW row;  
  10. static int query_error;  
  11. MySQL_RES *query_test(char *sql);  
  12. int query_show(MySQL_RES *result);  
  13. int main(int argc,char *argv[])  
  14. {  
  15. MySQL_RES * results;  
  16. results=query_test("select * from test");  

獲取記錄

  1. query_show(results); 

顯示記錄

  1. return 0;  

查詢記錄

  1. MySQL_RES *query_test(char *sql)  
  2. {  
  3. static MySQL_RES *query_result;  
  4. printf("%s\n",sql);  
  5. MySQL_init(&MySQL);  
  6. db_handel=MySQL_real_connect(&MySQL,DB_SERVER,DB_USER,DB_PWD,DB_NAME,0,0,0); 

打開讀取MySQL數(shù)據(jù)庫(kù)連接

  1. if(db_handel==NULL) 

錯(cuò)誤處理

{

 

  1. printf(MySQL_error(&MySQL));  
  2. return NULL;  
  3. }  
  4. query_error=MySQL_query(db_handel,sql);  

查詢

  1. if(query_error!=0) 

錯(cuò)誤處理

  1. {  
  2. printf(MySQL_error(db_handel));  
  3. return NULL;  
  4. }  
  5. query_result=MySQL_store_result(db_handel); 

獲取記錄

  1. MySQL_close(db_handel); 

關(guān)閉數(shù)據(jù)庫(kù)

  1. return query_result; 

返回記錄

 

 

顯示記錄

 

 

  1. int query_show(MySQL_RES *result)  
  2. {  
  3. unsigned int i,num_fields;  
  4. MySQL_FIELD *fileds;  
  5. num_fields=MySQL_num_fields(result);  

 

獲取字段數(shù)

 

 

  1. fileds=mysql_fetch_fields(result); 

獲取字段數(shù)組

 

 

  1. while((row=mysql_fetch_row(result))!=NULL) 

循環(huán)顯示

 

 

  1. {  
  2. for(i=0;i<num_fields;i++)  
  3. {  
  4. printf("%s: %s \n",fileds[i].name,row[i]?row[i]:"NULL");  
  5. }  
  6. }  
  7. return 0;  

 

以下是MakeFile文件內(nèi)容

  1. CC=gcc 
  2. #LDLIBS=`gtk-config --libs --cflags`  
  3. LDLIBS=-L /usr/lib/mysql -I /usr/include/mysql -l mysqlclient  
  4. CFLAGS=-Wall -g`gtk-config --cflags`  
  5. window:window.c  
  6. $(CC) $(LDLIBS) window.c -o window  
  7. #window.o:window.c  
  8. # $(CC) $(LDLIBS) -c window.c  
  9. clean:  
  10. rm -f window  
  11. rm -f *.o  

以上的相關(guān)內(nèi)容就是對(duì)c語(yǔ)言讀取Mysql的介紹,望你能有所收獲。

【編輯推薦】

  1. MySQL 資源的正確應(yīng)用
  2. MySQL數(shù)據(jù)庫(kù)的基本操作演示
  3. MySQL 免安裝版的實(shí)際配置方法
  4. 重置MySQL數(shù)據(jù)庫(kù)密碼的實(shí)際操作流程
  5. MySQL簡(jiǎn)單命令概述

 

責(zé)任編輯:佚名 來(lái)源: 博客園
相關(guān)推薦

2010-06-30 08:46:51

升級(jí)SQL Serve

2010-06-04 09:33:28

連接MySQL數(shù)據(jù)庫(kù)

2010-05-18 11:04:11

MySQL數(shù)據(jù)庫(kù)

2010-06-04 11:21:41

連接MySQL數(shù)據(jù)庫(kù)

2010-06-01 12:51:23

MySQL數(shù)據(jù)庫(kù)

2010-05-12 18:41:34

MySQL數(shù)據(jù)庫(kù)

2010-05-28 14:51:47

MySQL數(shù)據(jù)庫(kù)

2010-06-09 17:36:45

MySQL數(shù)據(jù)庫(kù)同步

2010-06-12 15:53:22

MySQL數(shù)據(jù)庫(kù)

2010-05-05 11:17:55

Oracle數(shù)據(jù)庫(kù)

2010-07-29 09:14:57

DB2數(shù)據(jù)庫(kù)表

2010-08-05 13:19:48

連接DB2數(shù)據(jù)庫(kù)

2010-08-12 11:38:21

DB2數(shù)據(jù)庫(kù)

2010-05-14 10:39:32

MySQL數(shù)據(jù)庫(kù)

2010-05-27 16:55:23

操作MySQL

2010-06-02 11:34:23

MySQL 數(shù)據(jù)庫(kù)導(dǎo)入

2011-04-26 10:24:27

C++MySQL

2011-04-26 10:37:04

C++MySQL

2010-06-02 16:20:08

2010-08-05 13:54:26

連接DB2數(shù)據(jù)庫(kù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)