C语言调用MySQL函数
MYSQL* m_pstConn;//为已建立的 MySQL数据库连接
MYSQL* m_pstConn;//为已建立的 MySQL数据库连接
// 获取表名
MYSQL_ROW tbl;
MYSQL_RES * pResultSet = NULL;
pResultSet = mysql_list_tables(m_pstConn, NULL);
while(tbl = mysql_fetch_row(pResultSet))
{
printf("table:%s\n", tbl[0]);
}
//获取数据库名
MYSQL_ROW db;
MYSQL_RES * pResultSet = NULL;
pResultSet = mysql_list_dbs(m_pstConn, NULL);
while(db= mysql_fetch_row(pResultSet))
{
printf("db:%s\n", db[0]);
}
//获取字段名
MYSQL_FIELD *tbl;
MYSQL_RES * pResultSet = NULL;
pResultSet = mysql_list_fields(m_pstConn, "test_log", NULL);
while(tbl = mysql_fetch_field(pResultSet))
{
printf("db:%s\n", tbl[0]);
}
//获取字段名
MYSQL_FIELD *tbl;
MYSQL_RES * pResultSet = NULL;
mysql_query(m_pstConn, "select * from test_log");
pResultSet = mysql_store_result(m_pstConn);
while(tbl = mysql_fetch_field(pResultSet))
{
printf("db:%s\n", tbl[0]);
}
//获取字段信息
MYSQL_FIELD *tbl;
MYSQL_RES * pResultSet = NULL;
mysql_query(m_pstConn, "select * from test_log");
pResultSet = mysql_store_result(m_pstConn);
while(tbl = mysql_fetch_field(pResultSet))
{
printf("db:%s, %d, %d, %s\n", tbl[0], tbl->type, tbl->flags, tbl->name);
}
上一篇: REQUEST 接收的有关问题