Windows connection MySQL

Source: Internet
Author: User
Int main (INT argc, char * argv []) {const char * Host = "localhost"; // host const char * user = "root "; // username const char * passwd = "12321"; // password const char * DB = "mydb"; // database name unsigned int Port = 3306; // MySQL port const char * unix_socket = 0; unsigned long client_flag = 0; MySQL; mysql_res * result; mysql_field * field; mysql_row SQL _row; string temp_time = getnewtime (3 ); string SQL _select = "select kid, keyword_hash, Keyword, record_time from words_realtime where record_time <'"+ temp_time +"' "; mysql_library_init (0, null, null); // initialize MySQL C apimysql_init (& MySQL ); mysql_options (& MySQL, mysql_set_charset_name, "GBK"); If (mysql_real_connect (& MySQL, host, user, passwd, DB, port, unix_socket, client_flag )) {cout <"database connection OK! "<Endl; int res = mysql_query (& MySQL, SQL _select.c_str (); If (! Res) {// mysql_query returns 0 cout after successful execution <"query success! "<Endl; Result = mysql_store_result (& MySQL); If (result) {int I, j; cout <" Number of result: "<(unsigned long) mysql_num_rows (result) <Endl; for (I = 0; field = mysql_fetch_field (result); I ++) // obtain the column name {cout <field-> name <"" ;}cout <Endl; while (SQL _row = mysql_fetch_row (result) {for (I = 0; I <mysql_num_fields (result); I ++) {cout <SQL _row [I] <"" ;}cout <Endl ;}}} else {cout <mysql_error (& MySQL) <Endl ;}} mysql_close (& MySQL); System ("pause"); Return 0 ;}

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.