函数查询地址
1. 初始化数据库
SQL* mysql_init(MYSQL *mysql);
// An initialized MYSQL* handler.
// NULL if there was insufficient memory to allocate a new object.
2. 连接数据库
MYSQL *
mysql_real_connect(MYSQL *mysql, //init返回值
const char *host, //主机名,默认NULL=localhost
const char *user, //用户名
const char *passwd, //密码
const char *db, //数据库名
unsigned int port, //接口,默认0
const char *unix_socket, //套接字,默认NULL
unsigned long client_flag); //标志位,默认0
// A MYSQL* connection handler if the connection was successful
// NULL if the connection was unsuccessful
//For a successful connection, the return value is the same as the value of the first argument.
3. 查询
int mysql_query(MYSQL *mysql,
const char *stmt_str); //查询语句
//Zero for success. Nonzero if an error occurred.
4. 保存
MYSQL_RES *
mysql_store_result(MYSQL *mysql);
//A pointer to a MYSQL_RES result structure with the results.
//NULL if the statement did not return a result set or an error occurred.
//检错: mysql_errno() returns nonzero, or mysql_field_count() returns zero.
5. 打印查询结果
// 获取行数
uint64_t mysql_num_rows(MYSQL_RES *result);
//Returns the number of rows in the result set
//检索
MYSQL_ROW mysql_fetch_row(MYSQL_RES *result);
//成功返回下一列数据对应的结构体
/*When used after mysql_store_result() or mysql_store_result_nonblocking(),
mysql_fetch_row() returns NULL if there are no more rows to retrieve.
When used after mysql_use_result(), mysql_fetch_row() returns NULL if there
are no more rows to retrieve or an error occurred. To determine whether an
error occurred, check whether mysql_error() returns a nonempty string or
mysql_errno() returns nonzero.*/
//遍历
unsigned int mysql_num_fields(MYSQL_RES *result);
//Returns the number of columns in a result set.
6. 释放查询结果
void mysql_free_result(MYSQL_RES *result);
7. 断开连接
void mysql_close(MYSQL *mysql);
NOTICE: 编译时链接动态库 -lmysqlclient