Create a mysql database note with c language under linux

  
 

The header file of ‘mysql.h’ must be included in the reference header file (must be the absolute address of mysql.h, generally in the include directory under mysql, take a closer look at where you are?*), I Is ubuntu9.04, some Linux versions under /usr/include/mysql/mysql.h may be under /usr/local/mysql/include/mysql/mysql.h.

---- For a brief description of several of these functions, please refer to the MySQL documentation for details:

---- 1. MYSQL *mysql_init(MYSQL *mysql)

---- Initialize a data structure of type MYSQL to prepare for executing mysql_real_connect(). Parameters

mysql is a pointer to the structure. If mysql is NULL, create and initialize a MYSQL data structure.

The newly created structure will be released in mysql_close().

---- If successful, return a pointer to the initialized MYSQL data structure, otherwise return NULL.

---- 2. MYSQL *mysql_real_connect(MYSQL *mysql, const char *host,

---- const char *user, const char *passwd, const char *db,

---- unsigned int port, const char *unix_socket, unsigned int client_flag)

---- Establish a connection with the MySQL database engine. Before performing further data operations, you must ensure that mysql_re

al_connect() returns successfully.

---- The parameter mysql is the return value of mysql_init();

---- The parameter host is the TCP/IP host name of the machine running the MySQL database engine, if NULL The default is “lo

calhost”;

---- The parameters user and passwd are the legal user and password of the MySQL database;

---- the parameter db is The database name of the connection;

---- The parameters port, unix_socket and client_flag generally take the default value.

---- 3. int mysql_query(MYSQL *mysql, const char *query)

---- Execute the SQL statement in the query string, the query must end with 0. Returns 0 if successful.

---- 4. MYSQL_RES *mysql_store_result(MYSQL *mysql)

---- Returns the result of SELECT, SHOW, DESCRIBE, EXPLAIN and other statements. The function creates a new MYSQL_

RES data structure and stores the result in the structure. If the query has no matching results, an empty data set is returned.

After processing the result set, you must call mysql_free_result().

---- If there is an error, return NULL, otherwise return a pointer to the MYSQL_RES structure.

---- 5. MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)

---- Retrieve the next record in the result set, or NULL if there are no records or errors. The number of fields in a record

can be obtained with mysql_num_fields(result). The value of each field can be arrayed from row[0] to row[mysql_nu

m_fields(result)-1] access.

---- In the link option of the project, add the interface library of c:mysqlliblibmysql.lib, copy libmysql.d

ll to the system of operating system
Under the directory (c:winntsystem32), you can compile and run.

---- At this point, a simple database application is developed. Of course, MySQL has a feature-rich AP

I, and you can view the documentation. In addition, if you need cross-platform portability, you can consider using MySQL's ODBC interface

. You can configure the ODBC connection properties of MySQL yourself, or you can download the myodbc-2.50.29-nt.zip toolkit to match

Copyright © Windows knowledge All Rights Reserved