下面贴一个mysql的库,叫做dmysql 解压缩以后,make ; make install 安装 然后编译程序的时候,包含dmysql.h头文件,加上 -ldmysql标识,即可
头里面定义了一个mysql数据库的结构体,
typedef struct _dmysql_info { char *host; /*host for database*/ char *user; /*user name for database*/ char *pswd; /*password to the account*/ char *dbbs; /*name of database*/ } dmysql_info;
int main( void ) { dmysql_info db; db.host="127.0.0.1"; /*host for database*/ db.user="root"; /*user name for database*/ db.pswd=""; /*password to the account*/ db.dbbs="mysql"; /*name of database*/
char *s_query="GRANT ALL ON *.* to 'dorainm'@'127.0.0.1' IDENTIFIED BY '******';"; char *s_sql="SELECT `user`,`host`,`password` FROM `user`;";