Common functions for operating Mysql Data in C Language

Source: Internet
Author: User

Common functions for operating Mysql Data in C Language

 

Required header file: # include <MySQL/MySQL. h>

Function: obtain or initialize a MySQL structure.

Function prototype: MySQL * mysql_init (MySQL * MySQL)

Function return value: A Starting MySQL * handle

Note: If the memory is insufficient, null is returned.

 

Required header file: # include <MySQL/MySQL. h>

Function: closes a server connection and releases the connection-related memory.

Function prototype: void mysql_close (MySQL * MySQL );

Function input value: mysql: Type pointer

Function return value: None

 

Required header file: # include <MySQL/MySQL. h>

Function: connect to a MySQL Server

Function prototype: MySQL * mysql_connect (MySQL * MySQL, const char * Host, const char * user, const char * passwd );

Function input value: MySQL indicates the address of an existing MySQL structure.

Host indicates the host name or IP address of the MySQL server.

User indicates the Login User Name

Passwd indicates the logon password.

Function return value: If the connection is successful, a MySQL * connection handle: if the connection fails, null

Note: This function is not recommended. Use mysql_real_connect () instead.

 

Required files: # include <MySQL/MySQL. h>

Function: 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 );

Function input value: MySQL indicates the address of an existing MySQL structure.

Host indicates the host name or IP address of the MySQL server.

User indicates the Login User Name

Passwd indicates the logon password.

DB indicates the database to be connected

Port indicates the TCP/IP Port of the MySQL server.

Unix_socket indicates the connection type

Client_flag indicates the mark of MySQL running ODBC database

Function return value: If the connection is successful, a MySQL * connection handle: if the connection fails, null

 

Required header file: # include <MySQL/MySQL. h>

Function: returns the number of rows affected by the latest update, delete, or insert query.

Function input value: mysql: Type pointer

Function return value: an integer greater than zero indicates the number of affected or retrieved rows. Zero indicates that there is no record of the WHERE clause in the partition query order or no query is executed yet;-1 indicates that an error is returned for a query or a SELECT query

 

Required header file: # include <MySQL/MySQL. h>

Function: queries a specified connection.

Function prototype: int mysql_query (MySQL * MySQL, const char * query );

Function input value: Query indicates the executed SQL statement.

Function return value: If the query is successful, it is zero and the error is non-zero.

Related functions: mysql_real_query

 

Required header file: # include <MySQL/MySQL. h>

Function: gets the result identifier for a result set without buffering.

Function prototype: mysql_res * mysql_use_result (MySQL * MySQL );

Function input value: mysql: Type pointer

Function return value: A mysql_res result structure. If an error occurs, the return value is null.

 

# Volume EE <MySQL/MySQL. h>

Retrieves the next row of a result set.

Mysql_row mysql_fetch_row (mysql_res * result );

Mysql_res: Structure pointer

The mysql_row structure of the next row. If no more rows can be retrieved or if an error occurs, null

 

# Include <MySQL/MySQL. h>

Returns the number of columns in the specified result set.

Unsigned int mysql_num_fields (mysql_res * res );

Pointer of mysql_res Structure

An unsigned integer that indicates the number of fields in the result set.

 

# Include <MySQL/MySQL. h>

Create a database

Int mysql_create_db (MySQL * MySQL, const char * dB );

MySQL: Type pointer

DB: name of the database to be created

If the database is successfully created, zero is returned. If an error occurs, the value is non-zero.

 

# Include <MySQL/MySQL. h>

Select a database

Int mysql_select_db (MySQL * MySQL, const char * dB );

MySQL: Type pointer

DB: name of the database to be created

If the database is successfully created, zero is returned. If an error occurs, the value is non-zero.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.