Gccmyapp. c-omyapp-Lusrlocallibmysql-lmysqlclient-If glibc is less than 2.3.0, you still need-lz; otherwise, the system prompts that MYSQL such as compress cannot be found: This structure represents a database connection handle. Almost all MySQL functions use it. You should not try to copy the MYSQL structure. There is no guarantee that such copying results will be
Gcc myapp. c-o myapp-L/usr/local/lib/mysql-lmysqlclient-If glibc is smaller than 2.3.0,-lz is required. Otherwise, the system prompts that MYSQL such as compress cannot be found: this structure represents a database connection handle. Almost all MySQL functions use it. You should not try to copy the MYSQL structure. There is no guarantee that such copying results will be
Gcc myapp. c-o myapp-L/usr/local/lib/mysql-lmysqlclient
-Lz is required if glibc is smaller than 2.3.0, otherwise the system prompts that compress and others cannot be found.
MYSQL:
This structure represents1Database connection handles. Almost allMySQLAll functions use it. Do not try copyingMYSQLStructure. It is not guaranteed that such copying results will be useful.
MYSQL_RES:
This structure indicates the query result of the returned row (SELECT, SHOW, DESCRIBE, EXPLAIN). In the rest of this Section, the Information returned by the query is called"Result set".
MYSQL_ROW:
This is1Row data"Type Security". It is currently implemented based on the array that counts byte strings. (If the field value may contain binary data, it cannot be treatedNullThe final string. This is because this type of value may containNullBytes ). The row is calledMysql_fetch_row ()Obtained.
MYSQL_FIELD:
This structure contains information about fields, such as field names, types, and sizes. Here we will detail its members. Repeated callMysql_fetch_field ()For each fieldMYSQL_FIELDStructure. The field values are not part of the structure. They are contained inMYSQL_ROWStructure.
MYSQL_FIELD_OFFSET:
This isMySQLOffset of the Field List"Type Security"IndicatesMysql_field_seek ()). Offset is the number of fields in the row, from0Start.
Preprocessing statements are mainly usedMYSQL_STMTAndMYSQL_BINDData structure. The3Type StructureMYSQL_TIMEUsed to transmit temporary data.
1. MYSQL_STMT
This structure indicates the preprocessing statement. By callingMysql_stmt_init ()Create a statement, return the statement handle, that is, pointingMYSQL_STMTPointer. This handle applies to all subsequent statements related to the user until the user usesMysql_stmt_close ()Close it.
MYSQL_STMTThe structure does not have parameters used by the supplied program. In addition, you should not try to copyMYSQL_STMTStructure. It is not guaranteed that such replicas will be useful.
Multiple statement handles can be associated with a single connection. The number of handles depends on system resources.
2. MYSQL_BIND
This structure is used for statement input (data value sent to the server) and output (result value returned from the server ). For input, it correspondsMysql_stmt_bind_param ()Used Together to bind the parameter data value to the bufferMysql_stmt_execute (). For the output, it correspondsMysql_stmt_bind_result ()Used Together to bind the result buffer for ease of useWith mysql_stmt_fetch ()To obtain rows.
MYSQL_BINDThe structure contains members used by the following suppliers. Each member is used for input and output, but can also be used for different purposes in some cases, depending on the direction of data transmission.
O enum enum_field_types buffer_type
The buffer type. The allowedBuffer_typeValue. For input,Buffer_typeSpecifies the value type associated with the statement parameters. For the output, it specifies the type of value you want to receive from the result buffer.
O void * buffer
For input, This is a buffer pointer to the data value of the stored statement parameter. For the output, it is a buffer pointer pointing to the value of the returned result set column. For the value column type, the buffer should point to the appropriateCType variable.UNSIGNEDAttribute columns, variablesUnsigned CType. UseIs_unsignedMember, indicating that the variable isSignedOrUnsignedType. For more information, see the following section ). For the date and time column types, the buffer should pointMYSQL_TIMEStructure. For character and binary string column types, the buffer should point to the character buffer zone.
O unsigned long buffer_length
* BufferIn bytes. It specifies the maximum data that can be stored in the buffer zone. For characters and binaryCData,Buffer_lengthTheMysql_stmt_bind_param ()Used Together* BufferLength, orMysql_stmt_bind_result ()The maximum data that can be extracted to the buffer zone when used together.
O unsigned long * length
PointUnsigned longPointer to the variable, which indicates that* BufferThe actual number of bytes of data."Length"Used for character or binaryCData. Bind the input parameter data,"Length"PointUnsigned longVariable, which indicates that* BufferThe length of the parameter value inMysql_stmt_execute (). Bind the output value,Mysql_stmt_fetch ()Will Save the returned column value"Length"To the variable.
For numeric and temporary data types,"Length"The reason is that the length of the data value isBuffer_typeValue.
O my_bool * is_null
This member pointsMy_boolVariable. If the value isNULL, The variable is"True"If the value is notNull, The variable is"False". For input, Set* Is_nullSet"True", Indicating that the parameter is passed in the form of statement ParametersNULLValue. For the output, if the returned result set column value isNULLWhen the row is obtained, the value is set"True".
"Is_null"Is a pointer to a boolean type, not a Boolean scalar, so that it can be used in the following ways:
§If the data value is alwaysNULL, UseMYSQL_TYPE_NULLBind a column.
§If the data value is alwaysNOT NULL, SetIs_null = (my_bool *) 0.
§In all other circumstancesIs_nullSetMy_boolAddress of the variable, and appropriately change the value of the variable between each execution to indicate that the data value isNULLOrNOT NULL.
O my_bool is_unsigned
This member is used for integer type. (CorrespondsMYSQL_TYPE_TINY,MYSQL_TYPE_SHORT,MYSQL_TYPE_LONG, AndMYSQL_TYPE_LONGLONGType Code ). For the unsigned type, Set"Is_unsigned"Set"True"For the signed type, set it"False".
O my_bool error
For the output, this member is used to report data truncation errors. TheMYSQL_REPORT_DATA_TRUNCATIONOptionalMysql_options ()To enable the truncation notification function. After this function is enabled,Mysql_stmt_fetch ()ReturnMYSQL_DATA_TRUNCATEDAnd for parameters with truncationMYSQL_BINDStructure, error flag is"True". Truncation indicates that the symbols, valid digits, or strings are too long to be contained in1Column.
To useMYSQL_BINDStructure, set its content0In order to initialize it, set it, and describe it properly. For example, to declare and initialize threeMYSQL_BINDThe following code can be used as an array of structures:
MYSQL_BIND bind [3];
Memset (bind, 0, sizeof (bind ));
3. MYSQL_TIME
This structure is usedDATE,TIME,DATETIMEAndTIMESTAMPData is directly sent to the server or directly received from the server. SetMYSQL_BINDStructureBuffer_typeSet the Member to one of the temporary values, and setBufferSet members to pointMYSQL_TIMEStructure.
MYSQL_TIMEThe structure contains the following members:
O unsigned int year
Year
O unsigned int month
Month
O unsigned int day
Days
O unsigned int hour
Hours
O unsigned int minute
Minutes
O unsigned int second
Seconds
O my_bool neg
Boolean indicates whether the time is negative.
O unsigned long second_part
Second. This member is not currently used.
Use onlyMYSQL_TIMEStructure: usedDATE,DATETIMEAndTIMESTAMPYear, month, and day. UsedTIME,DATETIMEAndTIMESTAMPThe hour, minute, and second of the value.
MYSQL_TIMERecdate;
MYSQL_BIND* M_param;
MYSQL_STMT* M_stmt;
MYSQL m_pDB;
CDatabase * m_pdb //Class
M_stmt = mysql_stmt_init (& (m_pdb-> m_pDB ))
MYSQL_STMT *Mysql_stmt_init ():The value returned by the initialization function.MYSQL_STMTThe data structure of the statement processing program. Note the return type.
Mysql_stmt_prepare ():Prepare for the operationSQLString.
Mysql_stmt_param_count ():Return preprocessingSQLThe number of parameters in the statement.
Mysql_stmt_bind_param ():Buffering and preprocessing Application DataSQLStatement.
Mysql_stmt_error ():Returns the error message of the last statement execution.
Mysql_stmt_execute ():Execute the pre-processing statement.
Mysql_stmt_close ():Release the memory used by the pre-processing statement.
CallMysql_stmt_init ()To create a statement handle, and then callMysql_stmt_preparePrepare the statement and callMysql_stmt_bind_param ()Provide parameter data and callMysql_stmt_execute ()Execute the statement. ChangeMysql_stmt_bind_param ()The parameter values in the corresponding buffer can be repeated.Mysql_stmt_execute ().
If the statement isSELECTOr any other statement that can generate a result set,Mysql_stmt_prepare ()Will also passMysql_stmt_result_metadata ()ToMYSQL_RESReturns metadata of the result set in the form of a result set.
You can useMysql_stmt_bind_result ()Provide result bufferingMysql_stmt_fetch ()The data is automatically returned to the buffer. This is a row-based acquisition method.
After the statement is executed, you must useMysql_stmt_close ()Close the statement handle so that all related resources can be released.
If you callMysql_stmt_result_metadata ()ObtainedSELECTStatement result set metadata should also be usedMysql_free_result ()Release metadata.
Procedure:
To prepare and execute statements, the application must take the following steps:
1.UseMsyql_stmt_init ()Create a preprocessing statement handle. To prepare preprocessing statements on the server, you can callMysql_stmt_prepare ()And pass the includeSQLStatement string.
2.If the statement generates a result set, callMysql_stmt_result_metadata ()To obtain the meta data of the result set. Although different from the result set that contains the returned columns, the metadata itself uses the result set form. The metadata result set specifies the number of columns in the result and the information of each column.
3.UseMysql_stmt_bind_param ()Set the value of any parameter. All parameters must be set. Otherwise, an error is returned for statement execution or unexpected results are generated.
4.CallMysql_stmt_execute ()Execute the statement.
5.If the statement generates a result set, bind the data buffer and callMysql_stmt_bind_result ()To retrieve the row value.
6.Repeated callMysql_stmt_fetch (), Extract data to the buffer by row until no more rows are found.
7.Repeat the steps by changing the parameter value and executing the statement again3To step6.
CallMysql_stmt_prepare (),MySQLThe Client/Server Protocol performs the following actions:
·The server parses the statement and uses the value assignment statement.IDSetOKStatus is sent back to the client. In addition, if it is a result-oriented statement, it also sends the total number of parameters, column counts, and metadata. During this call, the server checks all syntax and semantics of the statement.
·The client uses this statementIDIt is used for further operations so that the server can recognize statements from its statement pool.
CallMysql_stmt_execute (),MySQLThe Client/Server Protocol performs the following actions:
·The client uses the statement handle and sends the parameter data to the server.
·The server usesIDTo identify the statement, replace the parameter identifier with the new data, and execute the statement. If the statement generates a result set, the server sends the data back to the client. Otherwise, the server will sendOKStatus, as well as the total number of changes, deletions, and inserts.
CallMysql_stmt_fetch (),MySQLThe Client/Server Protocol performs the following actions:
·The client reads data from the information package by row and puts it into the application data buffer by performing necessary conversion operations. If the buffer type of the application is the same as the field type returned by the server, the conversion is very concise.
If an error occurs, you can useMysql_stmt_errno (),Mysql_stmt_error ()AndMysql_stmt_sqlstate ()Get statement error codes, error messages, andSQLSTATEValue.
Good Website:
Http://dev.mysql.com/doc/refman/5.1/zh/apis.html