{"id":34002,"date":"2024-11-25T15:49:41","date_gmt":"2024-11-25T07:49:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34002\/"},"modified":"2024-11-25T15:49:41","modified_gmt":"2024-11-25T07:49:41","slug":"%e5%b8%9d%e5%9b%bdcms%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e7%bd%91%e7%bb%9c%e8%bf%9e%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34002\/","title":{"rendered":"\u5e1d\u56fdcms\u5982\u4f55\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5"},"content":{"rendered":"<blockquote><p>\n  \u5e1d\u56fdcms \u901a\u8fc7\u7f51\u7edc\u8fde\u63a5\u529f\u80fd\u4ece\u5916\u90e8\u6570\u636e\u6e90\u83b7\u53d6\u6570\u636e\uff0c\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5305\u62ec\uff1a1. \u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\uff1b2. \u521b\u5efa\u7f51\u7edc\u8fde\u63a5\uff1b3. \u6267\u884c\u67e5\u8be2\uff1b4. \u83b7\u53d6\u7ed3\u679c\u3002\u4f7f\u7528 query \u548c fetch_array \u65b9\u6cd5\u6267\u884c\u67e5\u8be2\u5e76\u83b7\u53d6\u7ed3\u679c\uff0c\u5373\u53ef\u4ece\u5916\u90e8\u6570\u636e\u5e93\u83b7\u53d6\u6570\u636e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/17\/2024041703031512557.jpg\" class=\"aligncenter\" title=\"\u5e1d\u56fdcms\u5982\u4f55\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5\u63d2\u56fe\" alt=\"\u5e1d\u56fdcms\u5982\u4f55\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5e1d\u56fdCMS \u5982\u4f55\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5<\/strong><\/p>\n<p>\u5e1d\u56fdCMS\u662f\u4e00\u6b3e\u5f00\u6e90\u7684PHP\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff08CMS\uff09\uff0c\u63d0\u4f9b\u7f51\u7edc\u8fde\u63a5\u529f\u80fd\uff0c\u5141\u8bb8\u7528\u6237\u4ece\u5916\u90e8\u6570\u636e\u6e90\u83b7\u53d6\u6570\u636e\u3002<\/p>\n<p><strong>\u7528\u6cd5\uff1a<\/strong><\/p>\n<p><strong>1. \u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/p>\n<p>\u5728\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u7684 e\/config\/config.php \u6587\u4ef6\u4e2d\uff0c\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\uff1a<\/p>\n<pre>$dbhost = \"localhost\";\n$dbuser = \"root\";\n$dbpw = \"password\";\n$dbname = \"database_name\";<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u521b\u5efa\u7f51\u7edc\u8fde\u63a5<\/strong><\/p>\n<p>\u5728\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u7684 e\/class\/db.class.php \u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528 add_connect \u65b9\u6cd5\u521b\u5efa\u7f51\u7edc\u8fde\u63a5\uff1a<\/p>\n<pre>$linkid = @mysql_connect($dbhost, $dbuser, $dbpw, true);\nmysql_select_db($dbname, $linkid);\n$this-&gt;add_connect($linkid, true);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u6267\u884c\u67e5\u8be2<\/strong><\/p>\n<p>\u4f7f\u7528 query \u65b9\u6cd5\u6267\u884c\u67e5\u8be2\uff0c\u5176\u4e2d $sql \u662f\u8981\u6267\u884c\u7684 SQL \u8bed\u53e5\uff1a<\/p>\n<pre>$sql = \"SELECT * FROM table_name\";\n$result = $this-&gt;query($sql, $linkid);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u83b7\u53d6\u7ed3\u679c<\/strong><\/p>\n<p>\u4f7f\u7528 fetch_array \u65b9\u6cd5\u83b7\u53d6\u67e5\u8be2\u7ed3\u679c\uff1a<\/p>\n<pre>$row = $this-&gt;fetch_array($result);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u4ece\u5916\u90e8\u6570\u636e\u5e93\u83b7\u53d6\u6240\u6709\u7528\u6237\u6570\u636e\uff1a<\/p>\n<pre>$db = new db;\n\n\/\/ \u521b\u5efa\u7f51\u7edc\u8fde\u63a5\n$linkid = $db-&gt;add_connect($dbhost, $dbuser, $dbpw, $dbname);\n\n\/\/ \u6267\u884c\u67e5\u8be2\n$sql = \"SELECT * FROM users\";\n$result = $db-&gt;query($sql, $linkid);\n\n\/\/ \u83b7\u53d6\u7ed3\u679c\nwhile ($row = $db-&gt;fetch_array($result)) {\n    echo \"\u7528\u6237\u540d\uff1a\" . $row['username'] . \"&lt;br&gt;\";\n    echo \"\u5bc6\u7801\uff1a\" . $row['password'] . \"&lt;br&gt;&lt;br&gt;\";\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e1d\u56fdcms \u901a\u8fc7\u7f51\u7edc\u8fde\u63a5\u529f\u80fd\u4ece\u5916\u90e8\u6570\u636e\u6e90\u83b7\u53d6\u6570\u636e\uff0c\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5305\u62ec\uff1a1. \u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\uff1b2. \u521b\u5efa\u7f51\u7edc\u8fde\u63a5\uff1b3. \u6267\u884c\u67e5\u8be2\uff1b4. \u83b7\u53d6\u7ed3\u679c\u3002\u4f7f\u7528 query \u548c fetch_array \u65b9\u6cd5\u6267\u884c\u67e5\u8be2\u5e76\u83b7\u53d6\u7ed3\u679c\uff0c\u5373\u53ef\u4ece\u5916\u90e8\u6570\u636e\u5e93\u83b7\u53d6\u6570\u636e\u3002 \u5e1d\u56fdCMS \u5982\u4f55\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5 \u5e1d\u56fdCMS\u662f\u4e00\u6b3e\u5f00\u6e90\u7684PHP\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff08CMS\uff09\uff0c\u63d0\u4f9b\u7f51\u7edc\u8fde\u63a5\u529f\u80fd\uff0c\u5141\u8bb8\u7528\u6237\u4ece\u5916\u90e8\u6570\u636e\u6e90\u83b7\u53d6\u6570\u636e\u3002 \u7528\u6cd5\uff1a 1. \u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5 \u5728\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u7684 e\/config\/config.php \u6587\u4ef6\u4e2d\uff0c\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\uff1a $dbhost = &#8220;localhost&#8221;; $dbuser = &#8220;root&#8221;; $dbpw = &#8220;password&#8221;; $dbname = &#8220;database_name&#8221;; \u767b\u5f55\u540e\u590d\u5236 2. \u521b\u5efa\u7f51\u7edc\u8fde\u63a5 \u5728\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u7684 e\/class\/db.class.php \u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528 add_connect \u65b9\u6cd5\u521b\u5efa\u7f51\u7edc\u8fde\u63a5\uff1a $linkid = @mysql_connect($dbhost, $dbuser, $dbpw, true); mysql_select_db($dbname, $linkid); $this-&gt;add_connect($linkid, true); \u767b\u5f55\u540e\u590d\u5236 3. \u6267\u884c\u67e5\u8be2 \u4f7f\u7528 query \u65b9\u6cd5\u6267\u884c\u67e5\u8be2\uff0c\u5176\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-34002","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=34002"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34002\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}