c语言mysql编程

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C语言mysql编程

先给出一个简单的代码:可以实现最简单的数据库连接:

#include

#include

#include

static void output_error(MYSQL * mysql);

int main()

{

MYSQL mysql ;// 代码1

const char *host="localhost";

const char *user="root";

const char *password="zjh171";

const char *database="renshi";

const int port=3306;

const char *socket=NULL;

const int flag = 0;

mysql_init(&mysql);// 代码2

mysql_real_connect(&mysql,host,user,password,database,port,socket,flag) return 0;

}

代码1:

先看看MYSQL 是什么:

typedef struct st_mysql

{

NET net; /* Communication parameters */

unsigned char *connector_fd; /* ConnectorFd for SSL */

char *host,*user,*passwd,*unix_socket,*server_version,*host_info; char *info, *db;

struct charset_info_st *charset;

MYSQL_FIELD *fields;

MEM_ROOT field_alloc;

my_ulonglong affected_rows;

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

my_ulonglong extra_info; /* Not used */

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

unsigned long packet_length;

unsigned int p ort;

unsigned long client_flag,server_capabilities;

unsigned int p rotocol_version;

unsigned int f ield_count;

unsigned int server_status;

unsigned int server_language;

unsigned int w arning_count;

struct st_mysql_options options;

enum mysql_status status;

my_bool free_me; /* If free in mysql_close */

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

/* session-wide random string */

char scramble[SCRAMBLE_LENGTH+1];

/*

Set if this is the original connection, not a master or a slave we have

added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()

*/

my_bool rpl_pivot;

/*

Pointers to the master, and the next slave connections, points to

itself if lone connection.

*/

struct st_mysql* master, *next_slave;

struct st_mysql* last_used_slave; /* needed for round-robin slave pick */

/* needed for send/read/store/use result to work correctly with replication */ struct st_mysql* last_used_con;

LIST *stmts; /* list of all statements */

const struct st_mysql_methods *methods;

void *thd;

/*

Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag from mysql_stmt_close if close had to cancel result set of this object.

*/

my_bool *unbuffered_fetch_owner;

/* needed for embedded server - no net buffer to store the 'info' */

char *info_buffer;

void *extension;

} MYSQL;

显然是一个结构体;

相关文档
最新文档