This initializes an MYSQL object that can be used in the
Here is its syntax
MYSQL *mysql_init(MYSQL *object)
- If the object parameter that's passed is NULL, then the function initializes and returns a new object.
- Otherwise, the supplied object is initialized, and the address of the object is returned.
This function closes the previously opened MySQL connection. Here is its syntax
void mysql_close(MYSQL *mysqlObject)
- It de-allocates the connection handler that's represented by the
- The function returns no value.
This establishes a connection to a MySQL database engine running on the specified host. Here is its syntax.
MYSQL *mysql_real_connect(MYSQL *mysqlObject, const char *hostName, const char *userid, const char *password, const char *dbase, unsigned int port, const char *socket, unsigned long flag)
mysqlObjectrepresents the address of an existing MYSQL object.
hostNameis where the hostname or IP address of the host is provided. To connect to localhost, either NULL or the string localhost is provided.
useridrepresents a valid MySQL login ID.
passwordrepresents the password of the user.
dbaserepresents the database name to which the connection has to be established.
portis where either value 0 is specified, or the port number for the TCP/IP connection is supplied.
socketis where either NULL is specified, or the socket or named pipe is supplied.
flagcan be used to enable certain features, such as handling expired passwords and applying compression in the client/server protocol, but its value is usually kept at 0.
This frees the memory allocated to a result set. Here is its syntax.
void mysql_free_result(MYSQL_RES *resultset)
resultset represents the set whose memory we want to free up.
This function executes the supplied SQL query. Here is its syntax
int mysql_query(MYSQL *mysqlObject, const char *sqlstmt)
mysqlObjectrepresents the MYSQL object
sqlstmtrepresents the null-terminated string that contains the SQL statement to be executed.
- The function returns 0 if the SQL statement executes successfully. Otherwise, it returns a non-zero value.
After the successful execution of an SQL statement, this method is used to save the result set. This means that the result set is retrieved and returned. Here is its syntax
MYSQL_RES *mysql_use_result(MYSQL *mysqlObject)
mysqlObjectrepresents the connection handler.
- If no error occurs, the function returns an
- In case of any error, the function returns
This returns the number of values, that is, columns in the supplied row. Here is its syntax.
unsigned int mysql_num_fields(MYSQL_ROW row)
- Here, the parameter
rowrepresents the individual row accessed from the
This function fetches the next row from a result set. The function returns
NULL if there are no more rows in the result set to retrieve or an error occurs. Here is its syntax.
MYSQL_ROW mysql_fetch_row(MYSQL_RES *resultset)
- Here, the
resultsetparameter is the set from which the next row must be fetched.
- You can access values in the column of the row by using the subscript
row, and so on, where
rowrepresents the data in the first column,
rowrepresents the data in the second column, and so on.