{"id":194041,"date":"2024-11-13T03:16:20","date_gmt":"2024-11-12T19:16:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/194041\/"},"modified":"2024-11-13T03:16:21","modified_gmt":"2024-11-12T19:16:21","slug":"%e4%b8%80%e9%8d%b5%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e7%b0%a1%e5%8c%96%e4%bb%a3%e7%a2%bc%e6%89%93%e9%96%8b%e6%b5%81%e7%a8%8b%ef%bc%88%e4%bb%a3%e7%a2%bc%e6%89%93%e9%96%8b%e9%80%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/194041\/","title":{"rendered":"\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\uff0c\u7c21\u5316\u4ee3\u78bc\u6253\u958b\u6d41\u7a0b\uff08\u4ee3\u78bc\u6253\u958b\u9023\u63a5\u6578\u64da\u5eab\uff09"},"content":{"rendered":"<h1 id=\"%e4%b8%80%e9%8d%b5%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e7%b0%a1%e5%8c%96%e4%bb%a3%e7%a2%bc%e6%89%93%e9%96%8b%e6%b5%81%e7%a8%8b-IFngGmRNFq\">\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\uff0c\u7c21\u5316\u4ee3\u78bc\u6253\u958b\u6d41\u7a0b<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u8edf\u4ef6\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u5df2\u7d93\u6210\u70ba\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u61c9\u7528\u9084\u662f\u5927\u578b\u7cfb\u7d71\uff0c\u6578\u64da\u5eab\u90fd\u627f\u64d4\u8457\u5b58\u5132\u548c\u7ba1\u7406\u6578\u64da\u7684\u91cd\u4efb\u3002\u7136\u800c\uff0c\u9023\u63a5\u6578\u64da\u5eab\u7684\u904e\u7a0b\u5f80\u5f80\u9700\u8981\u7de8\u5beb\u7e41\u7463\u7684\u4ee3\u78bc\uff0c\u9019\u4e0d\u50c5\u589e\u52a0\u4e86\u958b\u767c\u7684\u8907\u96dc\u6027\uff0c\u4e5f\u53ef\u80fd\u5c0e\u81f4\u932f\u8aa4\u7684\u767c\u751f\u3002\u70ba\u4e86\u89e3\u6c7a\u9019\u4e00\u554f\u984c\uff0c\u8a31\u591a\u958b\u767c\u8005\u958b\u59cb\u5c0b\u6c42\u7c21\u5316\u6578\u64da\u5eab\u9023\u63a5\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u5176\u4e2d\u201c\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\u201d\u4fbf\u662f\u4e00\u500b\u6709\u6548\u7684\u65b9\u5f0f\u3002<\/p>\n<h2 id=\"%e4%b8%80%e9%8d%b5%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%a6%82%e5%bf%b5-IFngGmRNFq\">\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\u7684\u6982\u5ff5<\/h2>\n<p>\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\u7684\u6982\u5ff5\u662f\u6307\u901a\u904e\u7c21\u55ae\u7684\u914d\u7f6e\u6216\u8abf\u7528\u7279\u5b9a\u7684\u51fd\u6578\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u5efa\u7acb\u8207\u6578\u64da\u5eab\u7684\u9023\u63a5\uff0c\u800c\u7121\u9700\u624b\u52d5\u7de8\u5beb\u7e41\u7463\u7684\u9023\u63a5\u4ee3\u78bc\u3002\u9019\u7a2e\u65b9\u6cd5\u4e0d\u50c5\u63d0\u9ad8\u4e86\u958b\u767c\u6548\u7387\uff0c\u9084\u964d\u4f4e\u4e86\u51fa\u932f\u7684\u6a5f\u6703\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e7%b0%a1%e5%8c%96%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%b5%81%e7%a8%8b-IFngGmRNFq\">\u70ba\u4ec0\u9ebc\u9700\u8981\u7c21\u5316\u6578\u64da\u5eab\u9023\u63a5\u6d41\u7a0b<\/h2>\n<ul>\n<li><strong>\u63d0\u9ad8\u958b\u767c\u6548\u7387\uff1a<\/strong>\u958b\u767c\u8005\u53ef\u4ee5\u5c07\u66f4\u591a\u7684\u6642\u9593\u548c\u7cbe\u529b\u96c6\u4e2d\u5728\u696d\u52d9\u908f\u8f2f\u7684\u5be6\u73fe\u4e0a\uff0c\u800c\u4e0d\u662f\u5728\u6578\u64da\u5eab\u9023\u63a5\u7684\u7d30\u7bc0\u4e0a\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u932f\u8aa4\uff1a<\/strong>\u624b\u52d5\u7de8\u5beb\u9023\u63a5\u4ee3\u78bc\u5bb9\u6613\u51fa\u73fe\u932f\u8aa4\uff0c\u7c21\u5316\u6d41\u7a0b\u53ef\u4ee5\u964d\u4f4e\u9019\u7a2e\u98a8\u96aa\u3002<\/li>\n<li><strong>\u6613\u65bc\u7dad\u8b77\uff1a<\/strong>\u7c21\u5316\u7684\u4ee3\u78bc\u7d50\u69cb\u66f4\u5bb9\u6613\u7406\u89e3\u548c\u7dad\u8b77\uff0c\u7279\u5225\u662f\u5728\u5718\u968a\u5408\u4f5c\u4e2d\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%af%a6%e7%8f%be%e4%b8%80%e9%8d%b5%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab-IFngGmRNFq\">\u5982\u4f55\u5be6\u73fe\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab<\/h2>\n<p>\u5be6\u73fe\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\u7684\u65b9\u5f0f\u6709\u5f88\u591a\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u65b9\u6cd5\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8orm%e6%a1%86%e6%9e%b6-IFngGmRNFq\">1. \u4f7f\u7528ORM\u6846\u67b6<\/h3>\n<p>\u5c0d\u65bc\u8a31\u591a\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u4f7f\u7528\u5c0d\u8c61\u95dc\u4fc2\u6620\u5c04\uff08ORM\uff09\u6846\u67b6\u662f\u4e00\u500b\u7406\u60f3\u7684\u9078\u64c7\u3002ORM\u6846\u67b6\u5982Hibernate\u3001Entity Framework\u7b49\uff0c\u63d0\u4f9b\u4e86\u7c21\u55ae\u7684API\u4f86\u8655\u7406\u6578\u64da\u5eab\u9023\u63a5\u548c\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528Python\u7684SQLAlchemy\u6846\u67b6\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>from sqlalchemy import create_engine\n\n# \u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\nengine = create_engine('mysql+pymysql:\/\/username:password@localhost\/dbname')\nconnection = engine.connect()\n<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-IFngGmRNFq\">2. \u4f7f\u7528\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u53e6\u4e00\u7a2e\u7c21\u5316\u9023\u63a5\u7684\u65b9\u5f0f\u662f\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u4f86\u5b58\u5132\u6578\u64da\u5eab\u7684\u9023\u63a5\u4fe1\u606f\u3002\u9019\u6a23\uff0c\u958b\u767c\u8005\u53ea\u9700\u5728\u4ee3\u78bc\u4e2d\u8b80\u53d6\u914d\u7f6e\u6587\u4ef6\u5373\u53ef\u5efa\u7acb\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u4e00\u500bPHP\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n$config = parse_ini_file('config.ini');\n$conn = new mysqli($config['host'], $config['user'], $config['password'], $config['dbname']);\n?&gt;<\/code><\/pre>\n<h3 id=\"3-%e5%b0%81%e8%a3%9d%e9%80%a3%e6%8e%a5%e5%87%bd%e6%95%b8-IFngGmRNFq\">3. \u5c01\u88dd\u9023\u63a5\u51fd\u6578<\/h3>\n<p>\u958b\u767c\u8005\u9084\u53ef\u4ee5\u5c07\u6578\u64da\u5eab\u9023\u63a5\u7684\u908f\u8f2f\u5c01\u88dd\u6210\u4e00\u500b\u51fd\u6578\uff0c\u9019\u6a23\u5728\u9700\u8981\u9023\u63a5\u6578\u64da\u5eab\u6642\uff0c\u53ea\u9700\u8abf\u7528\u8a72\u51fd\u6578\u5373\u53ef\u3002\u4ee5\u4e0b\u662f\u4e00\u500bJava\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>public Connection connect() {\n    try {\n        String url = \"jdbc:mysql:\/\/localhost:3306\/dbname\";\n        String user = \"username\";\n        String password = \"password\";\n        return DriverManager.getConnection(url, user, password);\n    } catch (SQLException e) {\n        e.printStackTrace();\n        return null;\n    }\n}<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-IFngGmRNFq\">\u7d50\u8ad6<\/h2>\n<p>\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\u7684\u5be6\u73fe\u4e0d\u50c5\u80fd\u5920\u63d0\u9ad8\u958b\u767c\u6548\u7387\uff0c\u9084\u80fd\u6e1b\u5c11\u932f\u8aa4\uff0c\u4e26\u4f7f\u4ee3\u78bc\u66f4\u6613\u65bc\u7dad\u8b77\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\uff0c\u8d8a\u4f86\u8d8a\u591a\u7684\u5de5\u5177\u548c\u6846\u67b6\u51fa\u73fe\uff0c\u4f7f\u5f97\u9019\u4e00\u904e\u7a0b\u8b8a\u5f97\u66f4\u52a0\u7c21\u55ae\u548c\u9ad8\u6548\u3002\u5c0d\u65bc\u5e0c\u671b\u7c21\u5316\u958b\u767c\u6d41\u7a0b\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684\u5de5\u5177\u548c\u65b9\u6cd5\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u548c\u904b\u884c\u60a8\u7684\u670d\u52d9\u5668\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u9375\u9023\u63a5\u6578\u64da\u5eab\uff0c\u7c21\u5316\u4ee3\u78bc\u6253\u958b\u6d41\u7a0b\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\uff0c\u8b93\u6578\u64da\u64cd\u4f5c\u66f4\u4fbf\u6377\uff0c\u52a9\u529b\u5feb\u901f\u958b\u767c\u8207\u90e8\u7f72\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-194041","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/194041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=194041"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/194041\/revisions"}],"predecessor-version":[{"id":194042,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/194041\/revisions\/194042"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=194041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=194041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=194041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}