1. Makefile
INCLUDE =/usr/include/mysql/
LIBS =/usr/lib/mysql
All:
Gcc-I $ (INCLUDE)-L $ (LIBS)-lmysqlclient xxx. c-o xxx
Clean:
Rm-f xxx
2. mysql header file and library file configuration
If mysql is installed by default, configure it in Makefile
INCLUDE =/usr/include/mysql
LIBS =/usr/lib/mysql
If mysql is installed in/usr/local/mysql, configure
INCLUDE =/usr/local/mysql/include/mysql
LIBS =/usr/local/mysql/lib/mysql
If mysql is in the/usr/local/mysql directory, add a link. Otherwise, "libmysqlclient. so.16: cannot open shared object file: No such file or directory" may appear"
Ln-s/usr/local/mysql/lib/mysql/libmysqlclient. so.16/usr/lib/libmysqlclient. so.16
3. Unknown column 'opcode' in 'where clause'
Check whether the SQL statement is written incorrectly.
4. Commands out of sync; you can't run this command now
If You get Commands out of sync; You can't run this command now in your customer code, You are calling the customer function in the wrong order.
In the Code, to obtain the number of rows in the result, this error is reported using the following statement:
Mysql_real_query (mysql, SQL, strlen (SQL ));
Num = mysql_affected_rows (mysql );
Then I changed the statement to the following:
Mysql_real_query (mysql, SQL, strlen (SQL ));
Rs = mysql_store_result (mysql );
Num = mysql_num_rows (rs );
5. Mysql puts the query results in another table
Create another table first, and then
Insert into new_table select xxx, xxx, xxx from old_table where xxx;
6. query results
MYSQL * mysql;
MYSQL_RES * rs;
MYSQL_ROW row;
Char * SQL = "select uid, uname from users where uid = xxx ";
Mysql_real_connect (mysql, SQL, strlen (SQL );
Rs = mysql_store_result (mysql );
Row = mysql_fetch_row (rs );
The result is stored in the row. row [0] and row [1] are uid and uname, which can be used.
Atoi or atol converts the result to an integer.
7. "floating point exception" www.2cto.com appears during runtime
This occurs because there is a division of 0 in the Code. Check the code to judge whether the Division is 0.
Author: penyunwudong