I haven't made an original article in the last few days, all in the architecture server, write CGI program
The beginning took some days to Perl, and later found that the regular expressions of the scripting language, especially the special Bull X, were somewhat obscure ...
Back in C language to write efficient bar, anyway, I have written a lot of C library ...
Here is a MySQL library, called Dmysql
After decompression, make; Make install Installation
Then compile the program, including the dmysql.h header file, plus the-ldmysql logo, you can
The header defines the structure of a MySQL database,
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;
Data type of recordset
typedef struct _DMYSQL_RECORD
{
Char *s_str;
} Dmysql_record;
typedef struct _D_MYSQL_RES
{
int row;
int field;
Dmysql_row *s_row;
} dmysql_res;
and the error code at the time of the program running.
#define DMYSQL_QUERY_OKAY 0
#define DMYSQL_SELECT_OKAY 0
#define Dmysql_connect_error-1
#define Dmysql_init_error-2
#define Dmysql_query_error-3
#define Dmysql_res_error-4
The program has 3 functions in total.
extern int Dmysql_query (const char * s_query, const dmysql_info mysql_info);
Give an execution of the SQL command, such as update, INSERT, specify a database, you can
Pass in the address of a database recordset, give an SQL command for a select record, and then create a database, you can
To release the recordset space in memory that is declared in the stack.
extern void Dmysql_free (Dmysql_res *res);
The following is a demo program code:
#include <stdio.h>
#include <dmysql.h>
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 ' Hu Jintao ';";
Char *s_sql= "Select ' User ', ' host ', ' Password ' from ' user ';";
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.