C API function Description (S-W)

Source: Internet
Author: User

25.2.3.59. mysql_select_db ()

int mysql_select_db (MySQL *mysql, const char *db)

Describe

Causes the database specified by DB to be the default database (current database) on the connection specified by MySQL . In subsequent queries, the database will be the default database for table references that do not contain explicit database delimiters.

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

return value

0 indicates success, and a value other than 0 indicates an error occurred.

Error

· cr_commands_out_of_sync

The command was executed in an inappropriate order.

· cr_server_gone_error

The MySQL server is not available.

· cr_server_lost

The connection to the server was lost during the query process.

· cr_unknown_error

An unknown error has occurred.

25.2.3.60. Mysql_set_character_set ()

int Mysql_set_character_set (MySQL *mysql, char *csname)

Describe

This function is used to set the default character set for the current connection. The string csname Specifies 1 valid character set names. Connection proofing becomes the default proofing for character sets. The function works like a set NAMES statement, but it can also set the value of Mysql->charset , which affects the Mysql_real_ Escape_string () sets the character set.

This function is added in MySQL 5.0.7 .

return value

0 indicates success, and a value other than 0 indicates an error occurred.

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));
}
{
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)

Describe

The option to allow or disallow connections. option to take one of the following values:

mysql_option_multi_statements_on

Allow multi-statement support.

Mysql_option_multi_statements_off

Prohibit multi-statement support.

return value

0 indicates success, and a value other than 0 indicates an error occurred.

Error

· cr_commands_out_of_sync

The command was executed in an inappropriate order.

· cr_server_gone_error

The MySQL server is not available.

· cr_server_lost

The connection to the server was lost during the query process.

· er_unknown_com_error

The server does not support mysql_set_server_option ()(when the server version is less 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)

Describe

Requests that the database server be shut down. The connected user must have SHUTDOWN permissions. MySQL 5.1 server only supports 1 types of shutdown,shutdown_level must be equivalent to Shutdown_default. The design plans an additional shutdown level so that the desired level can be selected. For a dynamic link executable program that compiles and calls Mysql_shutdown () with an older version of the libmysqlclient header file, it needs to be libmysqlclient with the older version used in conjunction with dynamic libraries.

In section 5.5, "MySQL server shutdown process", the shutdown process is described.

return value

0 indicates success, and a value other than 0 indicates an error occurred.

Error

· cr_commands_out_of_sync

The command was executed in an inappropriate order.

· cr_server_gone_error

The MySQL server is not available.

· cr_server_lost

The connection to the server was lost during the query process.

· cr_unknown_error

An unknown error has occurred.

25.2.3.63. Mysql_sqlstate ()

const char *mysql_sqlstate (MySQL *mysql)

Describe

Returns a Null -terminated string that contains the SQLSTATE error code for the last error. The error code consists of 5 characters. ' 00000 ' means no error. Its value is specified by ANSI SQL and ODBC . For a list of possible values, see Appendix B: error codes and messages .

Note that not all MySQL errors are mapped to the SQLSTATE error code. The value ' HY000 '(generic error) is used for unmapped errors.

return value

A Null -terminated string containing the SQLSTATE error code.

See also:

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)

Describe

Using mysql_ssl_set (), you can establish a secure connection using SSL . It must be called before Mysql_real_connect () .

unless you are allowed in the client library OpenSSL supports it, otherwise mysql_ssl_set () does nothing.

Mysql is the connection handler returned from mysql_init () . the other parameters are specified as follows:

· key is the path name of the key file.

· cert is the path name of the certificate file.

· The CA is the path name of the certificate authorization file.

· capath is the pathname to the directory that contains the trusted SSL CA certificate given in PEM format.

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

For any unused SSL parameters, you can give it NULL.

return value

The function always returns 0. If the SSL setting is incorrect,mysql_real_connect () will return an error when you try to connect.

25.2.3.65. Mysql_stat ()

Char *mysql_stat (mysql *mysql)

Describe

Returns a string containing specific information similar to the information provided by the mysqladmin status command. This includes the uptime in seconds, the number of running threads, the number of problems, the number of reloads, and how many tables are open.

return value

The character set that describes the state of the server. If an error occurs, NULLis returned.

Error

· cr_commands_out_of_sync

The command was executed in an inappropriate order.

· cr_server_gone_error

The MySQL server is not available.

· cr_server_lost

The connection to the server was lost during the query process.

· cr_unknown_error

An unknown error has occurred.

25.2.3.66. Mysql_store_result ()

mysql_res *mysql_store_result (MYSQL *mysql)

Describe

For each query that successfully retrieved data (SELECT,SHOW,DESCRIBE,EXPLAIN,CHECK TABLE ), you must call Mysql_store_result () or mysql_use_result ().

For other queries, you do not need to call Mysql_store_result () or mysql_use_result (), but if you call Mysql_store_result in any case (), It also does not cause any damage or degraded performance. you can detect whether a query has no result set (more later) by checking whether Mysql_store_result () returns 0 .

If you want to know whether a 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 results of the query to the client, allocates 1 mysql_res structures, and places the results in the structure.

If the query does not return a result set,mysql_store_result () returns a Null pointer (for example, if the query is an INSERT statement ).

If the result set fails to be read,mysql_store_result () also returns a Null pointer. Mysql_errno () returns a non- 0 value by checking whether mysql_error () returns a non-empty string, or mysql_field_count ( returns 0to check if an error has occurred.

If no rows are returned, an empty result set is returned. (An empty result set setting differs from a null pointer as a return value.)

Once Mysql_store_result () is called and a result is obtained that is not a Null pointer, call mysql_num_rows () to find the number of rows in the result set.

You can call mysql_fetch_row () to get the rows in the result set, or call Mysql_row_seek () and Mysql_row_tell () To get or set the current row position in the result set.

Once you have completed the operation on the result set, you must call mysql_free_result ().

See section 25.2, 13.1, "why Mysql_store_result () sometimes returns null" when mysql_query () returns successfully .

return value

A collection of mysql_res results with multiple results. If an error occurs, NULLis returned.

Error

If successful,Mysql_store_result ( ) resets mysql_error ( ) and Mysql_errno ().

· cr_commands_out_of_sync

The command was executed in an inappropriate order.

· cr_out_of_memory

Memory overflow.

· cr_server_gone_error

The MySQL server is not available.

· cr_server_lost

The connection to the server was lost during the query process.

· cr_unknown_error

An unknown error has occurred.

25.2.3.67. mysql_thread_id ()

unsigned long mysql_thread_id (MySQL *mysql)

Describe

Returns the thread IDof the current connection. This value can be used as a parameter of Mysql_kill () to kill a thread.

If the connection is lost and re-connected using mysql_ping () , the thread ID will change. This means that you should not get the thread ID and save it for later use. It should be acquired when needed.

return value

The thread IDof the current connection.

Error

No.

25.2.3.68. Mysql_use_result ()

mysql_res *mysql_use_result (MYSQL *mysql)

Describe

For each query that successfully retrieves data (SELECT,SHOW,DESCRIBE,EXPLAIN), you must call the Mysql_store_result () or mysql_use_result ().

Mysql_use_result () retrieves the initialization result set, but does not actually read the result set to the client like Mysql_store_result () . It must be retrieved for each row by a call to mysql_fetch_row () . This will read the result directly from the server without saving it in a temporary table or in a local buffer, which is faster and uses less memory than Mysql_store_result () . The client allocates memory only for the current row and communication buffers, and the allocated memory can be increased to max_allowed_packet bytes.

On the other hand, if you are doing a lot of processing on the client side for each row, or sending the output to a screen where the user might type "^s" (Stop scrolling), you should not use Mysql_use_result (). This binds the server and prevents other threads from updating any tables (data obtained from such tables).

When using Mysql_use_result () , you must perform mysql_fetch_row ()until a NULL value is returned, otherwise, The rows that are not fetched are returned as part of the next search. the C API gives the command out of sync error, and if you forget to perform the operation, you will not be able to run the command.

Should not be used with results returned from Mysql_use_result () Mysql_data_seek (),Mysql_row_seek (), Mysql_row_tell (),mysql_num_rows ( ) or mysql_affected_rows (), and no other query should be issued until Mysql_use_ Result () is complete. (However, after all rows have been fetched,mysql_num_rows () will return exactly the number of rows fetched).

Once you have completed the operation on the result set, you must call mysql_free_result ().

With libmysqld embedded servers, memory utilization will be largely lost as each row is retrieved, because memory usage precedes the call to mysql_free_result () .

return value

Mysql_res The result structure. If an error occurs, NULLis returned.

Error

If successful,Mysql_use_result ( ) resets mysql_error ( ) and Mysql_errno ().

· cr_commands_out_of_sync

The command was executed in an inappropriate order.

· cr_out_of_memory

Memory overflow.

· cr_server_gone_error

The MySQL server is not available.

· cr_server_lost

The connection to the server was lost during the query process.

· cr_unknown_error

An unknown error has occurred.

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

Error

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

return value

Alarm count.

Error

No.

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.