红联Linux门户
Linux帮助

Linux环境MySQL的C编程一个小例子

发布时间:2010-04-19 14:56:45来源:红联作者:静静飞舞
要包含头文件 mysql.h
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "123456";
char *database = "sam";
Boycott 18:38:36
//save http packet info
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%s\n", mysql_error(conn));
return;
}

/* send SQL query */
sprintf(insert, "insert into response(HTTP, Date, Server, Cache_Control, Expires, Last_Modified, \
ETag, Accept_Ranges, Content_Length, Connection, Content_Type, File_Location) \
values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
_http, _date, _server, _cache_control, _expires, _last_modified,
_etag, _accept_ranges, _content_length, _connection, _content_type, file_name);
//printf("^^^^^^%s^^^^^^^\n", insert);
if (mysql_query(conn, insert)) {
fprintf(stderr, "%s\n", mysql_error(conn));
}

mysql_close(conn);
文章评论

共有 1 条评论

  1. liuchun12255 于 2010-05-14 14:38:44发表:

    把你的gcc编译方式贴出来呢!