C API function Descriptive narrative (S-W)

Source: Internet
Author: User

25.2.3.59.?mysql_select_db ()

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

Descriptive narrative

Causes the database specified by DB to be the default database (current database) on the connection specified by MySQL . In a maybe query. The database will be the default database that does not include a table reference that understands the database's distinguished character.

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

return value

0 indicates success. A value other than 0 indicates an error occurred.

Error

· ???????? Cr_commands_out_of_sync

The command was run in an inappropriate order.

· ???????? Cr_server_gone_error

MySQLserver 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)

Descriptive narrative

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 . This affects the character sets set by mysql_real_escape_string () .

This function was added in MySQL 5.0.7 .

return value

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

Demo Sample:

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)

Descriptive narrative

option to agree or disallow the connection. option to take one of the following values:

mysql_option_multi_statements_on

Agree to multi-statement support.

Mysql_option_multi_statements_off

Prohibit multi-statement support.

return value

0 indicates success. A value other than 0 indicates an error occurred.

Error

· ???????? Cr_commands_out_of_sync

The command was run in an inappropriate order.

· ???????? Cr_server_gone_error

MySQLserver is not available.

· ???????? Cr_server_lost

During the query process. The connection to the server is lost.

· ???????? Er_unknown_com_error

Server does not support mysql_set_server_option ()(when the server version number is below 4.1.1 ). Or, the server does not support the option you are trying to set.

? 25.2.3.62.? Mysql_shutdown ()

int Mysql_shutdown (MySQL *mysql, enum enum_shutdown_level shutdown_level)

Descriptive narrative

Requests that the database server be shut down. The connected user must have SHUTDOWN permissions. MySQL 5.1Server supports only 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 that compiles and calls Mysql_shutdown () with the old version number libmysqlclient header file, the program needs to be run with the old version of libmysqlclient Used in conjunction with dynamic libraries.

In verse 5.5. The shutdown process is described in "MySQLServer shutdown process".

return value

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

Error

· ???????? Cr_commands_out_of_sync

The command was run in an inappropriate order.

· ???????? Cr_server_gone_error

MySQLserver is not available.

· ???????? Cr_server_lost

During the query process. The connection to the server is lost.

· ???????? Cr_unknown_error

An unknown error has occurred.

25.2.3.63.?mysql_sqlstate ()

const char *mysql_sqlstate (MySQL *mysql)

Descriptive narrative

Returns a Null -terminated string that includes 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 .

Attention. 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 that includes the SQLSTATE error code.

See also:

Please refer to section 25.2.3.14, "Mysql_errno ()". Please refer to section 25.2.3.15, "mysql_error ()".

Please 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)

Descriptive narrative

Use mysql_ssl_set (). You can use SSL to establish a secure connection.

It must be called before Mysql_real_connect () .

unless you agree in the client library OpenSSL supports, otherwise mysql_ssl_set () does not do whatever.

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

· ???????? 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 path name that points to the folder. This folder includes a trusted SSL CA certificate given in PEM format.

· ???????? cipher is a list of agreed password for SSL encryption.

It can be given NULLfor any unused SSL parameters.

return value

The function always returns 0. Assume that the SSL setting is incorrect. When you try to connect,mysql_real_connect () returns an error.

25.2.3.65.?mysql_stat ()

Char *mysql_stat (mysql *mysql)

Descriptive narrative

Returns a string that includes specific information. This information is similar to the information provided by the mysqladmin status command.

Includes the uptime in seconds, and the number of running threads, the number of issues. The number of times to reload, and how many tables are open.

return value

Describes 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 run in an inappropriate order.

· ???????? Cr_server_gone_error

MySQLserver 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)

Descriptive narrative

For each query that successfully retrieves data (SELECT,SHOW,DESCRIBE,EXPLAIN,CHECK TABLE , and so on ) ), 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 (). However , assuming that Mysql_store_result () is invoked under any circumstances, it does not result in any damage or decreased performance. By checking whether mysql_store_result () returns 0, you can check whether the query has no result set (many others later).

Suppose you want to know whether a query should return a result set. can be checked using mysql_field_count () . Please refer to section 25.2.3.22, "Mysql_field_count ()".

Mysql_store_result () reads the entire result of the query to the client. Allocate 1 mysql_res Structures and place the results in the structure.

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

assuming the read result set fails,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 0, to check if an error has occurred.

Assuming 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 the Mysql_store_result () is called and a result is obtained that is not a Null pointer. You can call mysql_num_rows () to find the number of rows in the result set.

Ability to 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 the operation on the result set has been completed. mysql_free_result ()must be called.

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

return value

A collection of mysql_res results with multiple results.

If an error occurs, NULLis returned.

Error

Assume success. Mysql_store_result ( ) will reset mysql_error ( ) and Mysql_errno ().

· ???????? Cr_commands_out_of_sync

The command was run in an inappropriate order.

· ???????? cr_out_of_memory

Memory overflow.

· ???????? Cr_server_gone_error

MySQLserver 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)

Descriptive narrative

Returns the thread IDof the current connection.

This value can be used as a mysql_kill () to kill the thread.

Suppose the connection is lost and reconnected 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 required.

return value

The thread IDof the current connection.

Error

No.

25.2.3.68.?mysql_use_result ()

mysql_res *mysql_use_result (MYSQL *mysql)

Descriptive narrative

For each query that successfully retrieves data (SELECT,SHOW,DESCRIBE,EXPLAIN). You must call 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, faster and with less memory than Mysql_store_result () . The client allocates memory only for the current row and communication buffers, and the allocated memory can be added to max_allowed_packet bytes.

On the other hand, if you are doing a lot of processing for each row on one side of the client, 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 whatever tables (data obtained from such tables).

When using Mysql_use_result () . You must run mysql_fetch_row ()until a NULL value is returned, otherwise the rows that are not fetched are returned as part of the next retrieval. the C API gives the command out of sync errors. If you forget to run 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 enquiry shall be issued until Mysql_use_ Result () is complete. (However, when all rows are fetched,mysql_num_rows () returns exactly the number of rows fetched).

Once you have finished working on the result set, you must call mysql_free_result ().

When using libmysqld embedded server. Since memory usage will be added to each of the retrieved rows before calling Mysql_free_result () , the memory benefit will be largely lost.

return value

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

Error

assuming success,Mysql_use_result ( ) resets mysql_error ( ) and Mysql_errno ().

· ???????? Cr_commands_out_of_sync

The command was run in an inappropriate order.

· ???????? cr_out_of_memory

Memory overflow.

· ???????? Cr_server_gone_error

MySQLserver 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 run of the previous SQL statement.

return value

Alarm count.

Error

No.

C API function Descriptive narrative (S-W)

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.