{"id":4,"date":"2017-07-03T18:56:07","date_gmt":"2017-07-03T10:56:07","guid":{"rendered":"https:\/\/qtvz.com\/?p=4"},"modified":"2017-09-11T21:29:30","modified_gmt":"2017-09-11T15:29:30","slug":"%e6%b5%8b%e8%af%95%e6%96%87%e7%ab%a0","status":"publish","type":"post","link":"https:\/\/qtvz.com\/4.html","title":{"rendered":"C\/C++\u6570\u636e\u5e93\u8fde\u63a5\u67e5\u8be2\uff08MySql\u6570\u636e\u5e93\uff09"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u670b\u53cb\u7684\u4e00\u4e2a\u5c0f\u9879\u76ee\u9700\u8981\u67e5\u8be2<a href=\"https:\/\/qtvz.com\/tag\/%e6%95%b0%e6%8d%ae%e5%ba%93\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e \u6570\u636e\u5e93 \u7684\u6587\u7ae0\" target=\"_blank\">\u6570\u636e\u5e93<\/a>\u6570\u636e\uff0c\u5e2e\u5fd9\u5199\u4e86\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\u4f9b\u5927\u5bb6\u53c2\u8003\u4e00\u4e0b!<\/p>\n<pre class=\"lang:c decode:true\">\t\/\/ List<a href=\"https:\/\/qtvz.com\/tag\/c\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e C \u7684\u6587\u7ae0\" target=\"_blank\">C<\/a>trl\u63a7\u4ef6\r\n\tCListCtrl C_list_ctrl;\/\/\u63a7\u4ef6\u8c03\u7528\u663e\u793a\u6570\u636e\u65f6\u9700\u8981\u4f7f\u7528\r\n        FILE *fp;\r\n\tint n = 0;\r\n\tchar s2[100][20];\r\n\tfp = fopen(\"database.config\", \"r\");\r\n\tif ((fp = fopen(\"database.config\", \"r\")) == NULL)\r\n\t{\r\n\t\tMessageBox(\"\u8bfb\u53d6<a href=\"https:\/\/qtvz.com\/tag\/%e6%95%b0%e6%8d%ae%e5%ba%93\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e \u6570\u636e\u5e93 \u7684\u6587\u7ae0\" target=\"_blank\">\u6570\u636e\u5e93<\/a>\u914d\u7f6e\u6587\u4ef6\u5931\u8d25\\n\");\r\n\t\texit(1);\r\n\t}\r\n\twhile (1){\r\n\t\tfscanf(fp, \"%s\", s2[n]);\r\n\t\tif (feof(fp))break;\r\n\t\tn++;\r\n\t}\r\n\tfclose(fp);\r\n\tfp = NULL;\r\n\tDB_HOST=strstr(s2[1], \"=\");\r\n\tDB_PORT = strstr(s2[2], \"=\");\r\n\tDB_DATABASE = strstr(s2[3], \"=\");\r\n\tDB_USERNAME = strstr(s2[4], \"=\");\r\n\tDB_PASSWORD = strstr(s2[5], \"=\"); \r\n\tDB_TABLE = strstr(s2[6], \"=\");\r\n\tDB_CHARACTER = strstr(s2[7], \"=\");\r\n\t\/\/\u8fde\u63a5<a href=\"https:\/\/qtvz.com\/tag\/%e6%95%b0%e6%8d%ae%e5%ba%93\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e \u6570\u636e\u5e93 \u7684\u6587\u7ae0\" target=\"_blank\">\u6570\u636e\u5e93<\/a>\r\n\tMYSQL mysql;\r\n\tchar sql_insert[500];\r\n\tmysql_library_init(NULL, 0, 0);\r\n\tmysql_init(&amp;mysql);\r\n\tif (mysql_options(&amp;mysql, MYSQL_SET_CHARSET_NAME, ++DB_CHARACTER))\/\/\u8bbe\u7f6e\u5b57\u7b26\u96c6\r\n\t{\r\n\t\tMessageBox(\"\u8bbe\u7f6e\u5b57\u7b26\u96c6\u5931\u8d25\\n\\n\");\r\n\t}\r\n\tif (!mysql_real_connect(&amp;mysql, ++DB_HOST, ++DB_USERNAME, ++DB_PASSWORD, ++DB_DATABASE, 0, NULL, CLIENT_MULTI_STATEMENTS))\/\/\u8fde\u63a5\u6570\u636e\u5e93\r\n\t{\r\n\t\tMessageBox(\"\u8fde\u63a5<a href=\"https:\/\/qtvz.com\/tag\/mysql\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e MySql \u7684\u6587\u7ae0\" target=\"_blank\">MySql<\/a>\u6570\u636e\u5e93\u5931\u8d25\uff01\");\r\n\t}\r\n\tsprintf(sql_insert, \"select * from %s;\", ++DB_TABLE);\r\n\tmysql_query(&amp;mysql, sql_insert);          \/\/\u6267\u884cSQL\u8bed\u53e5\r\n\tMYSQL_RES *result = mysql_store_result(&amp;mysql);       \/\/\u83b7\u53d6\u8d44\u6e90\r\n\tmy_ulonglong rowcount = mysql_num_rows(result);        \/\/\u83b7\u53d6\u8bb0\u5f55\u6570\u884c\r\n\tunsigned int fieldcount = mysql_num_fields(result);   \/\/\u83b7\u53d6\u5b57\u6bb5\u6570\u5217\r\n\tMYSQL_FIELD *field = NULL;                            \/\/\u5b57\u6bb5\r\n\tMYSQL_ROW row = NULL;                         \/\/\u8bb0\u5f55\r\n\tmy_ulonglong y = 0;\r\n\twhile (row = mysql_fetch_row(result))\r\n\t{\r\n\r\n\t\tfor (my_ulonglong i = 0; i&lt;fieldcount; i++)\r\n\t\t{\r\n\t\t\tif (i == 0)C_list_ctrl.InsertItem(y, \"\", 0);\r\n\t\t\tC_list_ctrl.SetItemText(y, i, (CString)row[i]);\r\n\t\t}\r\n\t\ty++;\r\n\t}\r\n\tmysql_free_result(result);\r\n\tmysql_close(&amp;mysql);\r\n\tmysql_server_end();\r\n       \/\/mysql_library_end();\/\/\u8fd9\u6761\u8bed\u53e5\u52a0\u4e0a\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u610f\u5916\u5d29\u6e83<\/pre>\n<p>\u63d0\u793a\uff1a<\/p>\n<p>1\u3001\u6539\u7a0b\u5e8f\u5b57\u7b26\u96c6\u9700\u8981\u8bbe\u7f6e\u4e3a\uff08\u672a\u8bbe\u7f6e\u4e0d\u7136\u9700\u8981\u5bf9\u5bbd\u5b57\u7b26\u8fdb\u884c\u4f18\u5316\uff09<\/p>\n<p>2\u3001\u672c\u7a0b\u5e8f\u4f7f\u7528\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u7684\u5f62\u5f0f\u8fdb\u884c\u8fde\u63a5\u6570\u636e\u5e93\uff0c\u65b9\u4fbf\u4f7f\u7528<\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u670b\u53cb\u7684\u4e00\u4e2a\u5c0f\u9879\u76ee\u9700\u8981\u67e5\u8be2\u6570\u636e\u5e93\u6570\u636e\uff0c\u5e2e\u5fd9\u5199\u4e86\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\u4f9b\u5927\u5bb6\u53c2\u8003\u4e00\u4e0b! \/\/ ListCtrl\u63a7\u4ef6 CListCtrl C_list_ctrl;\/\/\u63a7\u4ef6\u8c03\u7528\u663e\u793a\u6570\u636e\u65f6\u9700\u8981\u4f7f\u7528 FILE *fp; in \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,12,5],"tags":[15,14,13],"views":24167,"_links":{"self":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/4"}],"collection":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/comments?post=4"}],"version-history":[{"count":3,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/4\/revisions"}],"predecessor-version":[{"id":15,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/4\/revisions\/15"}],"wp:attachment":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/media?parent=4"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/categories?post=4"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/tags?post=4"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}