Mysql串連的mysql結構

來源:互聯網
上載者:User

 

我們

在用mysql的c API時,用到最多的就是MYSQL結構了。毫無疑問這個結構是mysql c/c++編程的核心了。

 

以下是該結構的定義:

 

 

typedef struct st_mysql {

  NETnet;                                                          /* 網路連接參數 */

  gptrconnector_fd;                                         /* SSL 串連控制代碼 */

  char*host,*user,*passwd,*unix_socket,*server_version,*host_info,*info,*db;   // 串連參數

  unsigned intport,client_flag,server_capabilities;                   //串連參數

  unsigned intprotocol_version;

  unsigned intfield_count;            //列數

  unsigned int server_status;      // 

  unsigned long thread_id;                /* Id for connection in server */

  my_ulonglong affected_rows;         

  my_ulonglong insert_id;/* id if insert on table with NEXTNR */  

  my_ulonglong extra_info;/* Used by mysqlshow */

  unsigned long packet_length;

  enum mysql_status status;

  MYSQL_FIELD*fields;// the field info

  MEM_ROOTfield_alloc;// the field memory

  my_boolfree_me;/* If free in mysql_close */

  my_boolreconnect;/* set to 1 if automatic reconnect */

  struct st_mysql_options options;//option

  char       scramble_buff[9];// ??? 

  struct charset_info_st *charset;// charset info.

  unsigned int  server_language;// server language/

} MYSQL;

 

 

以下是net的定義,這個結構被用來進行網路讀寫:

 

typedef struct st_net {

  Vio* vio;

  my_socket fd;/* For Perl DBI/dbd */

  int fcntl;

  unsigned char *buff,*buff_end,*write_pos,*read_pos;

  char last_error[MYSQL_ERRMSG_SIZE];

  unsigned int last_errno,max_packet,timeout,pkt_nr;

  unsigned char error;

  my_bool return_errno,compress;

  my_bool no_send_ok; /* needed if we are doing several

   queries in one command ( as in LOAD TABLE ... FROM MASTER ),

   and do not want to confuse the client with OK at the wrong time

     */

  unsigned long remain_in_buf,length, buf_length, where_b;

  unsigned int *return_status;

  unsigned char reading_or_writing;

  char save_char;

} NET;

 

 

 

我們在進行mysql串連以及查詢時,MYSQL這個結構被用做傳送資訊的載體。

需要經常用到MYSQL結構的cAPI:

mysql_connect();

mysql_real_connect();

mysql_query();

mysql_store_result();

mysql_use_result();

mysql_error()

 

大家有興趣可以看看這幾個函數的實現,會有意想不到的收穫!

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.