亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2731 | 回復(fù): 0
打印 上一主題 下一主題

MySql 100104:Connector/C [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2010-01-04 20:27 |只看該作者 |倒序瀏覽

               

  Normal
  0
  
  7.8 磅
  0
  2
  
  false
  false
  false
  
   
   
   
   
   
   
   
   
   
   
   
   
  
  MicrosoftInternetExplorer4



/* Style Definitions */
table.MsoNormalTable
        {mso-style-name:普通表格;
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-parent:"";
        mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
        mso-para-margin:0cm;
        mso-para-margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:10.0pt;
        font-family:"Times New Roman";
        mso-ansi-language:#0400;
        mso-fareast-language:#0400;
        mso-bidi-language:#0400;}
table.MsoTableGrid
        {mso-style-name:網(wǎng)格型;
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        border:solid windowtext 1.0pt;
        mso-border-alt:solid windowtext .5pt;
        mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
        mso-border-insideh:.5pt solid windowtext;
        mso-border-insidev:.5pt solid windowtext;
        mso-para-margin:0cm;
        mso-para-margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        mso-pagination:none;
        font-size:10.0pt;
        font-family:"Times New Roman";
        mso-ansi-language:#0400;
        mso-fareast-language:#0400;
        mso-bidi-language:#0400;}
MySql 100104:Connector/C
@
http://zcatt.cublog.cn

1.框架
基本步驟:
a) mysql_library_init()
b)mysql_init()
c) Issue SQL statements and process their
results
d) mysql_close()
e) mysql_library_end()

The client can send SQL statement to the
server using mysql_query() or mysql_real_query() The diff is that mysql_query()
expects the query to be specified as a null-terminated string whereas
mysql_real_query() expects a counted string.
If the string contains binary data(which may include null bytes), you
must use mysql_real_query().
For SELECT queries, mysql_store_result()
get all the row returned from the server and stores them in the client. And
mysql_use_result() initiates a row-by-row result set, but does not actually get
any rows from the server.   In both
cases, you access rows by calling mysql_fetch_row().
After you are done with a result set, call
mysql_free_result() to free the memory used for it.

if using mysql_store_result, you can move
back and forth in the result set by using mysql_data_seek() or
mysql_row_seek(), and you can also find out how many rows there are by calling
mysql_num_rows().

2.主要函數(shù)


  
  id
  
  
  func
  
  
  Description
  


  
  1
  
  
  mysql_library_init()
  
  
  
初始化mysql
  library. 對于mysql單線程場景,可以忽略,mysql_init()默認會調(diào)用這個函數(shù)。對于多線程場景,應(yīng)當在起始時調(diào)用。
  


  
  2
  
  
  mysql_library_end()
  
  
  對應(yīng)mysql_library_end(),建議調(diào)用。
  


  
  3
  
  
  mysql_init()
  
  
  初始化MYSQL結(jié)構(gòu),
  


  
  4
  
  
  mysql_real_connect()
  
  
  
給定host,
  user, passwd, port,dbname等,連接mysql server。注意不應(yīng)當再使用過期的mysql_connect()
  


  
  5
  
  
  mysql_close()
  
  
  關(guān)閉連接。
  


  
  6
  
  
  mysql_store_result()
  
  
  查詢結(jié)果集合全部取回client
  


  
  7
  
  
  mysql_use_result()
  
  
  一行一行的取回查詢結(jié)果集合
  


  
  8
  
  
  mysql_free_result()
  
  
  釋放結(jié)果集合占用的內(nèi)存
  


  
  9
  
  
  mysql_fetch_row()
  
  
  取結(jié)果集合中的下一行
  


  
  10
  
  
  mysql_errno()
  
  
  錯誤碼
  


  
  11
  
  
  mysql_error()
  
  
  錯誤信息
  


3.例子
預(yù)備條件:
server上的賬戶 root:passwd@localhost:3306, 數(shù)據(jù)庫是world, 其中的表city結(jié)構(gòu)如下

mysql> desc
city;
+-------------+----------+------+-----+---------+----------------+
| Field       | Type     | Null | Key | Default | Extra          |
+-------------+----------+------+-----+---------+----------------+
| ID          | int(11)  | NO  
| PRI | NULL    | auto_increment |
| Name        | char(35) | NO   |   
|         |                |
| CountryCode |
char(3)  | NO   |   
|         |                |
| District    | char(20) | NO   |   
|         |                |
|
Population  | int(11)  | NO  
|     | 0       |                |
+-------------+----------+------+-----+---------+----------------+
5 rows in set
(0.00 sec)


程序如下

// mysqlTest.cpp : 定義控制臺應(yīng)用程序的入口點。
//

#include "stdafx.h"
#include "mysql.h"


#define MYSQL_PORT 3306
#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_PASSWD   "passwd"
#define MYSQL_DB   "world"

#define MYSQL_SELECTSTATEMENT    "select id, name, countrycode from city"


MYSQL mySQLHandler;

int _tmain(int argc, _TCHAR* argv[])
{

     unsigned
int r;
     MYSQL_RES *mySQLRes;
     MYSQL_ROW mySQLRow;
     
     mysql_library_init(0,NULL,NULL);

     mysql_init(&mySQLHandler);

     printf("1.
inited ---------------\n");

     if
(!mysql_real_connect(&mySQLHandler, MYSQL_HOST, MYSQL_USER, MYSQL_PASSWD,
MYSQL_DB,MYSQL_PORT, NULL, 0))
     {
         printf( "Error connecting to database: %s\n",mysql_error(&mySQLHandler));
         return
1;
     }

     printf("2.
connected ---------------\n");

     r =
mysql_real_query(&mySQLHandler, MYSQL_SELECTSTATEMENT, (unsigned long)
strlen(MYSQL_SELECTSTATEMENT));

     if(r)   
     {
         printf( "query err: %s\n",mysql_error(&mySQLHandler));
         return
1;
     }

     printf("3.queried
---------------\n");

     mySQLRes = mysql_store_result(&mySQLHandler);

     if
(!mySQLRes)     
     {
         printf( "store result err: %s\n",mysql_error(&mySQLHandler));
         return
1;
     }

     printf("3.stored
result ---------------\n");

     while(mySQLRow
= mysql_fetch_row(mySQLRes))
     {
         for(r=0;r
         {
              printf("%s ",mySQLRow[r]);
         }
         printf("\n");
     }

     printf("4.fetched
rows ---------------\n");
     mysql_free_result(mySQLRes);

     printf("5.free
result ---------------\n");

     mysql_close(&mySQLHandler);
     printf("6.close
mysql ---------------\n");

//   mysql_library_end();

     return
0;
}

               
               

本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/8866/showart_2139333.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP