CAPI function description (S-W)

Source: Internet
Author: User
25.2.3.59.mysql _ select_db () intmysql_select_db (MYSQL * mysql, constchar * db) Description makes the database specified by the db become the default database (current database) connected by the mysql ). In subsequent queries, the database will be the default database for table reference that does not contain clear database delimiters. Unless connected

25.2.3.59. mysql_select_db () int mysql_select_db (MYSQL * mysql, const char * db) Description makes the database specified by the db become the default database (current database) on the connection specified by mysql ). In subsequent queries, the database will be the default database for table reference that does not contain clear database delimiters. Unless connected

25.2.3.59. mysql_select_db ()

Int mysql_select_db (MYSQL * mysql, const char * db)

Description

Make the database specified by the Database become the default database (current database) connected by mysql ). In subsequent queries, the database will be the default database for table reference that does not contain clear database delimiters.

Unless the connected user has the permission to use the database, mysql_select_db () will fail.

Return Value

0 indicates success, and a non-0 value indicates an error.

Error

· CR_COMMANDS_OUT_OF_SYNC

The command is executed in an inappropriate order.

· CR_SERVER_GONE_ERROR

The MySQL server is unavailable.

· CR_SERVER_LOST

The connection to the server is lost during the Query Process.

· CR_UNKNOWN_ERROR

An unknown error occurs.

25.2.3.60. mysql_set_character_set ()

Int mysql_set_character_set (MYSQL * mysql, char * csname)

Description

This function is used to set the default character set for the current connection. The string csname specifies a valid Character Set Name. Connection proofreader is used as the default proofreader for character sets. This function works in a similar way as the set names statement, but it can also SET the value of mysql-> charset, thus affecting the character SET by mysql_real_escape_string.

This function is added in MySQL 5.0.7.

Return Value

0 indicates success, and a non-0 value indicates an error.

Example:

MYSQL mysql;
 
mysql_init(&mysql);
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
    fprintf(stderr, "Failed to connect to database: Error: %s\n",
          mysql_error(&mysql));
}
 
if (!mysql_set_charset_name(&mysql, "utf8")) 
{
    printf("New client character set: %s\n", mysql_character_set_name(&mysql));
}
25.2.3.61. mysql_set_server_option ()

Int mysql_set_server_option (MYSQL * mysql, enum enum_mysql_set_option option)

Description

The option to allow or disable connections. You can take one of the following values:

MYSQL_OPTION_MULTI_STATEMENTS_ON

Supports multiple statements.

MYSQL_OPTION_MULTI_STATEMENTS_OFF

Multiple statements are not supported.

Return Value

0 indicates success, and a non-0 value indicates an error.

Error

· CR_COMMANDS_OUT_OF_SYNC

The command is executed in an inappropriate order.

· CR_SERVER_GONE_ERROR

The MySQL server is unavailable.

· CR_SERVER_LOST

The connection to the server is lost during the Query Process.

· ER_UNKNOWN_COM_ERROR

The server does not support mysql_set_server_option () (when the server version is earlier than 4.1.1), or the server does not support the option that you are trying to set.

25.2.3.62. mysql_shutdown ()

Int mysql_shutdown (MYSQL * mysql, enum enum_shutdown_level shutdown_level)

Description

Request that the database server be shut down. The connected user must have the SHUTDOWN permission. MySQL 5.1 server only supports one shutdown type. shutdown_level must be equivalent to SHUTDOWN_DEFAULT. Additional shutdown levels are planned so that you can select the desired level. The dynamic link executable program that compiles and calls mysql_shutdown () using the header file of libmysqlclient of the old version must be used with the dynamic library of libmysqlclient of the old version.

In section 5.5, "MySQL server shutdown process" describes the shutdown process.

Return Value

0 indicates success, and a non-0 value indicates an error.

Error

· CR_COMMANDS_OUT_OF_SYNC

The command is executed in an inappropriate order.

· CR_SERVER_GONE_ERROR

The MySQL server is unavailable.

· CR_SERVER_LOST

The connection to the server is lost during the Query Process.

· CR_UNKNOWN_ERROR

An unknown error occurs.

25.2.3.63. mysql_sqlstate ()

Const char * mysql_sqlstate (MYSQL * mysql)

Description

Returns the string ending with Null, which contains the SQLSTATE error code of the last error. The error code contains five characters. '123' indicates no error. The value is specified by ansi SQL and ODBC. For a list of possible values, see Appendix B:Error code and message.

Note that not all MySQL errors are mapped to the SQLSTATE error code. The value 'hy000' (general error) is used for non- ing errors.

Return Value

String that contains the SQLSTATE error code ending with Null.

For more information, see:

See section 25.2.3.14, "mysql_errno ()". See section 25.2.3.15, "mysql_error ()". See section 25.2.7.26, "mysql_stmt_sqlstate ()".

25.2.3.64. mysql_ssl_set ()

Int mysql_ssl_set (MYSQL * mysql, const char * key, const char * cert, const char * ca, const char * capath, const char * cipher)

Description

Use mysql_ssl_set () to establish a secure connection over SSL. It must be called before mysql_real_connect.

Mysql_ssl_set () does nothing unless OpenSSL is supported in the client library.

Mysql is the connection handler returned from mysql_init. Other parameters are specified as follows:

· Key is the path name of the key file.

· Cert is the path name of the Certificate file.

· Ca is the path name of the certificate authorization file.

· Capath is the path name pointing to a directory that contains a trusted ssl ca certificate in pem format.

· Cipher is a list of allowed passwords for SSL encryption.

NULL can be specified for any unused SSL parameter.

Return Value

The total return value of this function is 0. If the SSL settings are incorrect, mysql_real_connect () will return an error when you try to connect.

25.2.3.65. mysql_stat ()

Char * mysql_stat (MYSQL * mysql)

Description

Returns a string containing specific information.Mysqladmin statusThe command provides similar information. Including the normal running time in seconds, the number of running threads, the number of problems, the number of reloads, and the number of opened tables.

Return Value

Character Set that describes the server status. If an error occurs, NULL is returned.

Error

· CR_COMMANDS_OUT_OF_SYNC

The command is executed in an inappropriate order.

· CR_SERVER_GONE_ERROR

The MySQL server is unavailable.

· CR_SERVER_LOST

The connection to the server is lost during the Query Process.

· CR_UNKNOWN_ERROR

An unknown error occurs.

25.2.3.66. mysql_store_result ()

MYSQL_RES * mysql_store_result (MYSQL * mysql)

Description

You must call mysql_store_result () or mysql_use_result () for each query (SELECT, SHOW, DESCRIBE, EXPLAIN, and check table) that successfully retrieves data ().

For other queries, you do not need to call mysql_store_result () or mysql_use_result (). However, if mysql_store_result () is called under any circumstances, it will not cause any damage or performance degradation. By checking whether mysql_store_result () returns 0, you can check whether there is no result set in the query (more in the future ).

If you want to know whether the query should return a result set, you can use mysql_field_count () to check. See section 25.2.3.22, "mysql_field_count ()".

Mysql_store_result () reads all the query results to the client, assigns a MYSQL_RES structure, and places the results in this structure.

If no result set is returned for the query, mysql_store_result () returns a Null pointer (for example, if the query is an INSERT Statement ).

If the read result set fails, mysql_store_result () returns a Null pointer. By checking whether mysql_error () returns a non-empty string, mysql_errno () returns a non-0 value, or mysql_field_count () returns 0, you can check whether an error has occurred.

If no row is returned, an empty result set is returned. (Null result set settings are different from null pointers used as return values ).

Once mysql_store_result () is called and the result is not a Null pointer, you can use mysql_num_rows () to find the number of rows in the result set.

You can call mysql_fetch_row () to obtain rows in the result set, or call mysql_row_seek () and mysql_row_tell () to obtain or set the current row position in the result set.

Once the operation on the result set is completed, mysql_free_result () must be called ().

See section 25.2.13.1, "Why does mysql_store_result () sometimes return NULL after mysql_query () returns success?”.

Return Value

A set of MYSQL_RES results with multiple results. If an error occurs, NULL is returned.

Error

If the operation succeeds, mysql_store_result () will reset mysql_error () and mysql_errno ().

· CR_COMMANDS_OUT_OF_SYNC

The command is executed in an inappropriate order.

· CR_OUT_OF_MEMORY

Memory overflow.

· CR_SERVER_GONE_ERROR

The MySQL server is unavailable.

· CR_SERVER_LOST

The connection to the server is lost during the Query Process.

· CR_UNKNOWN_ERROR

An unknown error occurs.

25.2.3.67. mysql_thread_id ()

Unsigned long mysql_thread_id (MYSQL * mysql)

Description

Returns the ID of the currently connected thread. This value can be used as the parameter of mysql_kill () to kill the thread.

If the connection is lost and mysql_ping () is used for reconnection, the thread ID changes. This means you should not get the thread ID and save it for future use. It should be obtained as needed.

Return Value

The ID of the currently connected thread.

Error

None.

25.2.3.68. mysql_use_result ()

MYSQL_RES * mysql_use_result (MYSQL * mysql)

Description

You must call mysql_store_result () or mysql_use_result () for each query (SELECT, SHOW, DESCRIBE, and EXPLAIN) that successfully retrieves data ().

Mysql_use_result () Will initialize the result set retrieval, but will not actually read the result set to the client as mysql_store_result () does. It must retrieve each row by calling mysql_fetch_row. This will directly read the results from the server, instead of saving them in a temporary table or local buffer, which is faster and uses less memory than mysql_store_result. The client only allocates memory for the current row and communication buffer. The allocated memory can be increased to max_allowed_packet bytes.

On the other hand, if you are processing a large number of rows on the client side, or sending the output to a screen where the user may type "^ S" (stop scrolling, you should not use mysql_use_result (). This binds the server and prevents other threads from updating any table (data is obtained from such tables ).

When using mysql_use_result (), you must execute mysql_fetch_row () until NULL value is returned. Otherwise, unobtained rows are returned as part of the next search. The c api command is not synchronized. If you forget to execute this operation, you cannot run this command.

Do not use mysql_data_seek (), mysql_row_seek (), counts (), mysql_num_rows (), or counts () together with the results returned from mysql_use_result (), or issue other queries until mysql_use_result () complete. (However, After all rows are extracted, mysql_num_rows () returns the extracted rows accurately ).

Once the operation on the result set is completed, mysql_free_result () must be called ().

When using the libmysqld Embedded Server, the memory usage will basically lose as each retrieval row increases before mysql_free_result () is called.

Return Value

MYSQL_RES result structure. If an error occurs, NULL is returned.

Error

If the operation succeeds, mysql_use_result () will reset mysql_error () and mysql_errno ().

· CR_COMMANDS_OUT_OF_SYNC

The command is executed in an inappropriate order.

· CR_OUT_OF_MEMORY

Memory overflow.

· CR_SERVER_GONE_ERROR

The MySQL server is unavailable.

· CR_SERVER_LOST

The connection to the server is lost during the Query Process.

· CR_UNKNOWN_ERROR

An unknown error occurs.

25.2.3.69. mysql_warning_count () unsigned int mysql_warning_count (MYSQL * mysql)

Error

Returns the number of alarms generated during execution of the previous SQL statement.

Return Value

Alarm count.

Error

None.

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.