Connect MySQL with C language under Windows attention issues

Source: Internet
Author: User

In the original: Windows under the C language connection MySQL attention issues

Environment is: After VS6.0 installed MySQL, we need the corresponding header file and Lib file, so the installation process must be a full installation. Otherwise, the Include folder is not generated Oh ~ The steps are as follows: 1. Fully install MySQL so that the Include folder can be generated. 2. Select "Includefiles" in the "Show directories for" drop-down list on the right side of the Directories tab and add the Include directory path to your local MySQL installation in the intermediate list box. That indicates what functions the API interface of MySQL has. The path to my machine is: C:\Program files\mysql\mysql Server 5.0\include3. Tell the compiler where the executable files for these API functions are (Libmysql.dll). Choose the Options option under the Tools menu, select "Libraryfiles" in the "Showdirectories for" drop-down list on the right side of the Directories tab, and add the Lib directory path where you installed MySQL locally. C:\Program files\mysql\mysql Server 5.0\lib\debug or C:\ProgramFiles\MySQL\MySQL server 5.0\lib\opt, mine is under the first one. According to the situation to find. 4. Select "Project settings->link:object/librarymodules" to add "Libmysql.lib"Or add directly to the program header: #pragma comment (lib, "Libmysql")
Note:Libmysql.dll and Libmysql.lib under C:\Program files\mysql\mysql Server5.0\lib\debug are best copied to the development directory, or run-time errors may be thrown.
========== below, add a small example: =========== #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <winsock2.h> #pragma comment (lib, "ws2_32") #pragma comment (lib, "Libmysql") #include "mysql.h"int main (int argc, char* argv[]) {int res,j;Mysqlmysql;Mysql_res *resultset;Mysql_row ROW;Mysql_init (&mysql);//Initialize MySQL structureConnect this machine, username is root, password is hope, database is hope, Port is 3306if (!Mysql_real_connect (&mysql, "localhost", "root", "hope", "Hope", 3306, NULL, 0)){printf ("\ n database connection Error!");} Else{printf ("\ n database connection succeeded!\n");Insert a piece of data into the database res = mysql_query (&mysql, "Insert intostudent (Name,age,rollno) VALUES (' Elisa ', 33, ' 3 ')");if (!res){ printf ("Insert%lu row data successfully!\n", (Unsignedlong) mysql_affected_rows (&mysql));}else printf ("Insert data failed!\n"); if (mysql_query (&mysql, "select *from Student")) {printf ("Error occurred in database Query");} else{Retrieving data printf ("\ nthe query data is: \ n");resultset= Mysql_store_result (&mysql);//Get result setif (mysql_num_rows (resultset) = NULL){int numrows = mysql_num_rows (resultset);//Get the number of records in the result set int numfields = Mysql_num_fields (resultset);//Get the number of fields in the table printf ("Total% d Row Records,%d fields per line. ", NumRows, numfields); j = 1;while (row= mysql_fetch_row (resultset)) {int i = 0; printf ("\ n%d line:", j); for (i = 0; i < numfields; i++){ fprintf (stdout, "%s", Row[i]); Print field values}j + +; }}Else {printf ("\ n no query results!");}Mysql_free_result (resultset);Releasing the result set }}Mysql_close (&mysql); Releasing a database connectionFgetchar (); return 0;}

Connect MySQL with C language under Windows attention issues

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.