{"id":143,"date":"2009-04-10T15:50:07","date_gmt":"2009-04-10T07:50:07","guid":{"rendered":"http:\/\/orczhou.com\/?p=143"},"modified":"2009-07-29T19:34:45","modified_gmt":"2009-07-29T11:34:45","slug":"windows-c-mysql","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2009\/04\/windows-c-mysql\/","title":{"rendered":"windows\u4e0b\u5982\u4f55\u4f7f\u7528C\u8bed\u8a00\u8fde\u63a5MySQL"},"content":{"rendered":"<p><a href=\"http:\/\/www.mysql.com\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-151\" title=\"logo_mysql_sun_a\" src=\"http:\/\/orczhou.com\/wp-content\/uploads\/2009\/04\/logo_mysql_sun_a.gif\" alt=\"logo_mysql_sun_a\" width=\"114\" height=\"68\" \/><\/a>\u5bf9\u4e8e\u521a\u521a\u63a5\u89e6<a href=\"http:\/\/www.mysql.com\" target=\"_blank\">MySQL<\/a>\u7684\u7528\u6237\uff0c\u5982\u679c\u60f3\u7528C\u8bed\u8a00\u8fde\u63a5<a href=\"http:\/\/www.mysql.com\" target=\"_blank\">MySQL<\/a>\uff0c\u5f80\u5f80\u4f1a\u662f\u4e00\u4ef6\u5f88\u9ebb\u70e6\u7684\u4e8b\u60c5\u3002\u8fd9\u91cc\u5c31\u6574\u7406\u8fc7\u7a0b\u505a\u4e00\u4e2a\u8be6\u7ec6\u7684\u8bf4\u660e\uff0c\u4ee5\u4fbf\u53c2\u8003\u3002<!--more--><\/p>\n<p><span class=\"partstart\">\u6982\u8ff0:<\/span><\/p>\n<p><a href=\"http:\/\/www.mysql.com\" target=\"_blank\">MySQL<\/a>\u4e3aC\u8bed\u8a00\u63d0\u4f9b\u4e86\u8fde\u63a5\u6570\u636e\u5e93\u7684<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/zh\/apis.html#c\" target=\"_blank\">API<\/a>\uff0c\u5982\u8fde\u63a5\u6570\u636e\u5e93\uff1a<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\">MYSQL mysql<span style=\"color: #339933;\">;<\/span>\nmysql_init<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span>mysql<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\nmysql_options<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span>mysql<span style=\"color: #339933;\">,<\/span>MYSQL_READ_DEFAULT_GROUP<span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;your_prog_name&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">!<\/span>mysql_real_connect<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span>mysql<span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;host&quot;<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;user&quot;<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;passwd&quot;<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;database&quot;<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span>NULL<span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n    <span style=\"color: #000066;\">fprintf<\/span><span style=\"color: #009900;\">&#40;<\/span>stderr<span style=\"color: #339933;\">,<\/span> <span style=\"color: #ff0000;\">&quot;Failed to connect to database: Error: %s<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>&quot;<\/span><span style=\"color: #339933;\">,<\/span>\n          mysql_error<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span>mysql<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p>\u8981\u60f3\u6b63\u5e38\u4f7f\u7528\u8fd9\u4e9bAPI\uff0c\u4f60\u9700\u8981\u505a\u4e00\u4e0b\u4e24\u4ef6\u4e8b\u60c5:<\/p>\n<ul>\n<li>\u5305\u542b\u8fd9\u4e9bAPI\u7684\u58f0\u660e\u6587\u4ef6(mysql.h)<\/li>\n<li>\u8ba9\u4f60\u7f16\u8bd1\u5668\u627e\u5230\u8fd9\u4e9bAPI\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u3002(dll\u5e93)<\/li>\n<\/ul>\n<p><span class=\"partstart\">\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/span><\/p>\n<ol>\n<li>\u5728\u4f60\u7684C\u8bed\u8a00\u4e2d\u52a0\u5165\u5982\u4e0b\u58f0\u660e:\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #339933;\">#include &quot;windows.h&quot;<\/span>\n<span style=\"color: #339933;\">#include &quot;mysql.h&quot;<\/span>\n<span style=\"color: #993333;\">int<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n......\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p><span style=\"font-family: Georgia; line-height: 19px; white-space: normal; \">\u90a3\u7f16\u8bd1\u5668\u5982\u4f55\u624d\u80fd\u627e\u5230mysql.h\u6587\u4ef6\u5462\uff1f\u9700\u8981\u505a\u5982\u4e0b\u8bbe\u7f6e: <\/span><\/p>\n<p><span style=\"line-height: 19px; white-space: normal;\"><span style=\"color: #ff0000;\"><span style=\"color: #ff0000;\">a)<\/span> <\/span><\/span><span style=\"font-family: Georgia; line-height: 19px; white-space: normal; \">VC6.0\u4e2d\uff0c\u5728\u4f60\u7684Project\uff08\u9879\u76ee\uff09\uff0c\u9009\u62e9<\/span><span style=\"line-height: 19px; white-space: normal;\"><span style=\"color: #008000;\">Tools<\/span><\/span><span style=\"font-family: Georgia; line-height: 19px; white-space: normal; \">\u83dc\u5355\u4e0b\u7684<\/span><span style=\"line-height: 19px; white-space: normal;\"><span style=\"color: #008000;\">Options<\/span><\/span><span style=\"font-family: Georgia; line-height: 19px; white-space: normal; \">\u9009\u9879\uff0c\u5728<\/span><span style=\"line-height: 19px; white-space: normal;\"><span style=\"color: #008000;\">Directories<\/span><\/span><span style=\"font-family: Georgia; line-height: 19px; white-space: normal; \">\u7684\u6807\u7b7e\u9875\u4e2d\u53f3\u8fb9\u7684\u201c<\/span><span style=\"line-height: 19px; white-space: normal;\"><span style=\"color: #008000;\">Show directories for:<\/span><\/span><span style=\"font-family: Georgia; line-height: 19px; white-space: normal; \">\u201d\u4e0b\u62c9\u5217\u8868\u4e2d\u9009\u4e2d\u201c<\/span><span style=\"line-height: 19px; white-space: normal;\"><span style=\"color: #008000;\">Includefiles<\/span><\/span><span style=\"font-family: Georgia; line-height: 19px; white-space: normal; \">\u201d\uff0c\u7136\u540e\u5728\u4e2d\u95f4\u5217\u8868\u6846\u4e2d\u6dfb\u52a0\u4f60\u672c\u5730\u5b89\u88c5MySQL\u7684include\u76ee\u5f55\u8def\u5f84\u3002\u00a0(5.*\u7248\u672c\u7684\u8def\u5f84\u5e94\u8be5\u662f:<\/span><span style=\"line-height: 19px; white-space: normal;\"><span style=\"color: #008000;\">C:\\\\Program Files\\\\MySQL\\\\MySQL Server 5.0\\\\include<\/span><\/span>)<\/p>\n<p><span style=\"color: #ff0000;\">b)<\/span>\u81f3\u6b64\uff0c\u4f60\u7684\u7f16\u8bd1\u5668\u5c31\u77e5\u9053mysql\u7684API\u63a5\u53e3\u6709\u54ea\u4e9b\u51fd\u6570\uff0c\u4ee5\u53ca\u51fd\u6570\u7684\u539f\u578b\u662f\u600e\u6837\u7684(mysql.h\u4e2d)\u3002\u4f60\u7684C\u8bed\u8a00\u7a0b\u5e8f\u5e94\u8be5\u5df2\u7ecf\u80fd\u591f\u901a\u8fc7Compile(\u7f16\u8bd1)\u8fd9\u4e00\u6b65\u4e86<\/li>\n<li>\u5230\u4e0a\u4e00\u6b65\u4f60\u7684\u7a0b\u5e8f\u80fd\u591f\u7f16\u8bd1\u901a\u8fc7\u4e86\uff0c\u4f46\u662f\u4e5f\u53ea\u662f\u80fd\u7f16\u8bd1\u800c\u5df2\uff0c\u60f3\u751f\u6210\u53ef\u6267\u884c\u7a0b\u5e8f<a href=\"http:\/\/www.tenouk.com\/ModuleW.html\" target=\"_blank\">\u8fd9\u4e9b\u8fd8\u4e0d\u591f<\/a>\u3002\u8fd8\u9700\u8981\u544a\u8bc9\u7f16\u8bd1\u5668\u8fd9\u4e9bAPI\u51fd\u6570\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5728\u54ea\u513f(libmysql.dll)\u3002<br \/>\nVC6.0\u4e2d\uff0c\u5728\u4f60\u7684Project\uff08\u9879\u76ee\uff09\u4e2d<\/p>\n<p><span style=\"color: #ff0000;\"> a) <\/span>\u9009\u62e9<span style=\"color: #008000;\">Tools<\/span>\u83dc\u5355\u4e0b\u7684<span style=\"color: #008000;\">Options<\/span>\u9009\u9879\uff0c\u5728<span style=\"color: #008000;\">Directories<\/span>\u7684\u6807\u7b7e\u9875\u4e2d\u53f3\u8fb9\u7684\u201c<span style=\"color: #008000;\">Show directories for:<\/span>\u201d\u4e0b\u62c9\u5217\u8868\u4e2d\u9009\u4e2d\u201c<span style=\"color: #008000;\">Library files<\/span>\u201d\uff0c\u7136\u540e\u6dfb\u52a0\u4f60\u672c\u5730\u5b89\u88c5MySQL\u7684Lib\u76ee\u5f55\u8def\u5f84\u3002\u00a0(5.*\u7248\u672c\u7684\u8def\u5f84\u5e94\u8be5\u662f:<span style=\"color: #008000;\">C:\\\\Program Files\\\\MySQL\\\\MySQL Server 5.0\\\\lib\\\\debug \u6216\u8005C:\\\\Program Files\\\\MySQL\\\\MySQL Server 5.0\\\\lib\\\\opt<\/span>)\uff1b<\/p>\n<p><span style=\"color: #ff0000;\"> b)<\/span> \u9009\u62e9\u201c<span style=\"color: #008000;\">Project settings-&gt;Link:Object\/library modules<\/span>\u201d\uff0c\u6dfb\u52a0\u201c<span style=\"color: #008000;\">libmysql.lib<\/span>\u201d \u00a0 \u00a0 [\u628a\u5efa\u8bae\u5c06\u201c<span style=\"color: #008000;\">libmySQL.lib\u3001libmySQL.dll<\/span>\u201d\u62f7\u5230\u4f60\u6240\u5efa\u7684\u5de5\u7a0b\u7684\u76ee\u5f55\u4e0b]<\/p>\n<p><span style=\"color: #ff0000;\"> c)<\/span> \u5728\u4f60\u7684\u7a0b\u5e8f\u4ee3\u7801\u4e2d\u52a0\u5165:<br \/>\n<span style=\"color: #008000;\"> #include &#8220;mysql.h&#8221;<br \/>\n#include &#8220;windows.h&#8221;<br \/>\n#pragma comment(lib,&#8221;libmySQL.lib&#8221;) <\/span><\/li>\n<li>\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86\u6240\u6709\u7684\u5de5\u4f5c\uff0c\u4f60\u7684\u6e90\u4ee3\u7801\u5927\u6982\u662f\u8fd9\u4e2a\u6837\u5b50\uff1a\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #339933;\">#include &quot;windows.h&quot;<\/span>\n<span style=\"color: #339933;\">#include &quot;mysql.h&quot;<\/span>\n<span style=\"color: #339933;\">#pragma comment(lib,&quot;libmySQL.lib&quot;)<\/span>\n<span style=\"color: #993333;\">int<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n\tMYSQL mysql<span style=\"color: #339933;\">;<\/span>\n\tmysql_init<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span>mysql<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n\tmysql_options<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span>mysql<span style=\"color: #339933;\">,<\/span>MYSQL_READ_DEFAULT_GROUP<span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;your_prog_name&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n\t<span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">!<\/span>mysql_real_connect<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span>mysql<span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;host&quot;<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;user&quot;<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;passwd&quot;<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;database&quot;<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span>NULL<span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n\t\t<span style=\"color: #000066;\">fprintf<\/span><span style=\"color: #009900;\">&#40;<\/span>stderr<span style=\"color: #339933;\">,<\/span> <span style=\"color: #ff0000;\">&quot;Failed to connect to database: Error: %s<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>&quot;<\/span><span style=\"color: #339933;\">,<\/span>mysql_error<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">&amp;<\/span>amp<span style=\"color: #339933;\">;<\/span>mysql<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n\t<span style=\"color: #009900;\">&#125;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<\/li>\n<li> \u5982\u679c\u4f60\u4f7f\u7528\u7684Dev C++\u60c5\u51b5\u53ef\u80fd\u4f1a\u590d\u6742\u4e9b\uff0c\u53ef\u4ee5\u53c2\u8003:<br \/>\n<a href=\"http:\/\/16hot.blog.isyi.com\/post\/1\/144\">http:\/\/16hot.blog.isyi.com\/post\/1\/144<\/a><br \/>\n<a href=\"http:\/\/topic.csdn.net\/u\/20080524\/01\/2a26ab3f-caee-4695-9141-d75b28995a2d.html\">http:\/\/topic.csdn.net\/u\/20080524\/01\/2a26ab3f-caee-4695-9141-d75b28995a2d.html<\/a><br \/>\n\u53e6\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u8fde\u63a5MySQL\u7684C++\u7c7b\u4e5f\u975e\u5e38\u597d\u7528:<a href=\"http:\/\/tangentsoft.net\/mysql++\/\">MySQL++<\/a><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-164\" title=\"logo-small\" src=\"http:\/\/orczhou.com\/wp-content\/uploads\/2009\/04\/logo-small.jpg\" alt=\"logo-small\" width=\"300\" height=\"142\" \/><\/li>\n<\/ol>\n<p>\u3010\u53c2\u8003\u6587\u7ae0\u3011<\/p>\n<ol>\n<li><a href=\"http:\/\/16hot.blog.isyi.com\/post\/1\/144\" target=\"_blank\">http:\/\/16hot.blog.isyi.com\/post\/1\/144<\/a><\/li>\n<li><a href=\"http:\/\/tech.ddvip.com\/2007-07\/118529907130315_2.html\">http:\/\/tech.ddvip.com\/2007-07\/118529907130315_2.html<\/a><\/li>\n<li><a href=\"http:\/\/www.tenouk.com\/ModuleW.html\">http:\/\/www.tenouk.com\/ModuleW.html<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8e\u521a\u521a\u63a5\u89e6MySQL\u7684\u7528\u6237\uff0c\u5982\u679c\u60f3\u7528C\u8bed\u8a00\u8fde\u63a5MySQL\uff0c\u5f80\u5f80\u4f1a\u662f\u4e00\u4ef6\u5f88\u9ebb\u70e6\u7684\u4e8b\u60c5\u3002\u8fd9\u91cc\u5c31\u6574\u7406\u8fc7\u7a0b\u505a\u4e00\u4e2a\u8be6\u7ec6\u7684\u8bf4\u660e\uff0c\u4ee5\u4fbf\u53c2\u8003\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6],"tags":[],"class_list":["post-143","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=143"}],"version-history":[{"count":27,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/143\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/143\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}