C language mysql programming note

Source: Internet
Author: User

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

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.