{"id":1282,"date":"2014-08-07T20:13:19","date_gmt":"2014-08-07T12:13:19","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=1282"},"modified":"2014-08-07T20:13:19","modified_gmt":"2014-08-07T12:13:19","slug":"vc%e6%93%8d%e4%bd%9cmysql%e7%9a%84%e5%85%b8%e5%9e%8b%e4%be%8b%e5%ad%90","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/1282","title":{"rendered":"vc\u64cd\u4f5cmysql\u7684\u5178\u578b\u4f8b\u5b50"},"content":{"rendered":"

vc\u64cd\u4f5cmysql\u7684\u5178\u578b\u4f8b\u5b50
\n1.\u5305\u542b\u6587\u4ef6<\/p>\n

\r\n#include \"mysql.h\"\r\n<\/pre>\n

2.\u521d\u59cb\u5316\u6570\u636e\u5e93<\/p>\n

\r\n\t\/\/\u5f00\u59cb\u94fe\u63a5\u6570\u636e\u5e93\r\n\t\/\/MYSQL mysql;\/\/\u5b9a\u4e49\u6210\u5168\u5c40\u7684\r\n\tmysql_init(&mysql);\r\n\tmysql_options(&mysql, MYSQL_SET_CHARSET_NAME, \"utf-8\"); \r\n\r\n\tif(!mysql_real_connect(&mysql,\"localhost\",\"user\",\"password\",\"user_db\",3306,NULL,0))\r\n\t{\r\n\t\tAfxMessageBox(\"\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25\");\r\n\t}\r\n\telse\r\n\t{\r\n\t\t\/\/MessageBox(\"\u94fe\u63a5\u6570\u636e\u5e93\u6210\u529f\uff01\");\r\n\t}\r\n<\/pre>\n

3.\u63d2\u5165\u6570\u636e<\/p>\n

\r\n\t\/\/\u6dfb\u52a0\u5230\u6570\u636e\u5e93\r\n\t\r\n\tCString strSQL = \"insert into xbzq.group values(NULL,'test');\";\r\n\tconst char * q =strSQL;\r\n\tmysql_query(&mysql,q);\r\n<\/pre>\n

4.\u8bfb\u51fa\u6570\u636e<\/p>\n

\r\n\tstrsql = \"select * from sentence_lib where id = \" + m_nId;\r\n\tmysql_query(&mysql,strsql);\r\n\tres = mysql_store_result(&mysql);\r\n\tMYSQL_ROW row=NULL;\r\n\trow = mysql_fetch_row(res);\r\n\tstrpassage = strpassage+row[1];\r\n\r\n\r\n\r\n<\/pre>\n

\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<\/p>\n

\r\n\t\/\/\u4ece\u6570\u636e\u5e93\u4e2d\u968f\u673a\u53d6\u51fa\u4e00\u4e2a\u53e5\u5b50\r\n\tCString strsql=\"select * from sentence_lib\";\r\n\tconst char * q =strsql;\r\n\tmysql_query(&mysql,q);\r\n\r\n\tMYSQL_RES *res = mysql_store_result(&mysql);\r\n\r\n\t\/\/mysql_use_result(MYSQL *mysql);\r\n\r\n\tint nRow = res->row_count;\/\/\u5f97\u5230\u7ec4\u6587\u7ae0\u7528\u7684\u53e5\u5b50\u5e93\u7684\u6570\u91cf\r\n\t\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

vc\u64cd\u4f5cmysql\u7684\u5178\u578b\u4f8b\u5b50 1.\u5305\u542b\u6587\u4ef6 #include “mysql.h” 2.\u521d\u59cb\u5316\u6570\u636e\u5e93 \/\/\u5f00\u59cb\u94fe\u63a5\u6570\u636e\u5e93 \/\/MYSQL mysql;\/\/\u5b9a\u4e49\u6210\u5168\u5c40\u7684 mysql_init(&mysql); mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, “utf-8″); if(!mysql_real_connect(&mysql,”localhost”,”user”,”password”,”user_db”,3306,NULL,0)) { AfxMessageBox(“\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25”); } else { \/\/MessageBox(“\u94fe\u63a5\u6570\u636e\u5e93<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,9],"tags":[202,144,156],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1282"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=1282"}],"version-history":[{"count":1,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1282\/revisions"}],"predecessor-version":[{"id":1283,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1282\/revisions\/1283"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=1282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=1282"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=1282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}