Just finished the course design, also indicates that the holiday is coming soon. This course design is not difficult, nothing is to make a XXX system, to achieve user registration, login, menu management, super users and so on some functions, so far has done several, so the basic process are familiar with! I think the most important thing to summarize is: C language and database connection, this piece of content! Because it was previously implemented with files.
★ Platform
This course is designed mainly for:
VC + + 6.0
Mysql-5.0.18-win32
Navicat for MySQL (MySQL graphical tool)
★ Configuration
Before writing the code, let the compiler know some of the MySQL database's APIs, which requires some path to the database to be configured on the VC. From the Internet to find a relatively good reference.
★ Database API functionsMysql_init ()
Prototype:MySQL *mysql_init (mysql *mysql)
Function: Primarily used to initialize MySQL objects
●Mysql_real_connect ()
Prototype: MySQL *mysql_real_connect (MySQL *mysql, const char *host, const char *user, const char *PASSWD, const char *DB, Unsigne d int port, const char *unix_socket, unsigned long Client_flag)
Function: Used to connect a MySQL database server, MySQL structure address is the &mysql,host hostname or address is "localhost", the username is "root", the password is "root", the database is "test", the port is "3306".
Mysql_store_result ()
Prototype: Mysql_res *mysql_store_result (MYSQL *mysql)
Role: Retrieving data, getting the result set in the database
●mysql_num_rows ()
Prototype: mysql_num_rows (Mysql_res *result)
effect: Gets the number of records in the result set. Generally mysql_num_rows () is in mysql_store_result (), mysql_num_rows () are mysql_store_result ().
mysql_fetch_row ()
< Span style= "FONT-FAMILY:VERDANA,GENEVA,ARIAL,HELVETICA,SANS-SERIF; line-height:19.5px ">< Span style= "FONT-FAMILY:VERDANA,GENEVA,ARIAL,HELVETICA,SANS-SERIF; LINE-HEIGHT:19.5PX "> prototype: mysql_row mysql_fetch_row (mysql_res *result)
< Span style= "FONT-FAMILY:VERDANA,GENEVA,ARIAL,HELVETICA,SANS-SERIF; line-height:19.5px "> action: Obtain a record in the result set, and each time it is executed, a row of records is removed. Similarly, its parameters with mysql_num_rows () same
★c Array passed to SQL statement
When writing to the registration function encountered a problem, studied for a long time. The problem is this: in the C language, the user information I entered (including ID number, name, password) is stored in the array, and in the database functions only in this form:
< Span style= "FONT-FAMILY:VERDANA,GENEVA,ARIAL,HELVETICA,SANS-SERIF; font-size:12px; line-height:19.5px "> mytable is the table name in the database, the parentheses are the fields in the table, after the values are the data to be inserted, But the user's registration information is stored in the character array, how can I convert the data inside the character array into the data that conforms to the SQL statement?
Find a lot of information, finally let me find a function:sprintf ()
its usage:
First of all to apply for a character array, assuming that sql_insert[50], its role is to write to this array later data, the user registration information is first written into this array.
And then:
This allows the user registration information to be inserted into the database. Where Sql_insert is the above-mentioned array, followed by the SQL statement.
Examples of query information: