{"id":170,"date":"2018-10-13T17:58:05","date_gmt":"2018-10-13T09:58:05","guid":{"rendered":"https:\/\/wp.dj47.top\/?p=170"},"modified":"2021-10-20T16:19:02","modified_gmt":"2021-10-20T08:19:02","slug":"mysql%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84%e6%9c%80%e4%bd%b321%e6%9d%a1%e7%bb%8f%e9%aa%8c","status":"publish","type":"post","link":"https:\/\/www.djlog.cn\/?p=170","title":{"rendered":"MySQL\u6027\u80fd\u4f18\u5316\u7684\u6700\u4f7321\u6761\u7ecf\u9a8c"},"content":{"rendered":"<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4eca\u5929\uff0c\u6570\u636e\u5e93\u7684\u64cd\u4f5c\u8d8a\u6765\u8d8a\u6210\u4e3a\u6574\u4e2a\u5e94\u7528\u7684\u6027\u80fd\u74f6\u9888\u4e86\uff0c\u8fd9\u70b9\u5bf9\u4e8eWeb\u5e94\u7528\u5c24\u5176\u660e\u663e\u3002\u5173\u4e8e\u6570\u636e\u5e93\u7684\u6027\u80fd\uff0c\u8fd9\u5e76\u4e0d\u53ea\u662fDBA\u624d\u9700\u8981\u62c5\u5fc3\u7684\u4e8b\uff0c\u800c\u8fd9\u66f4\u662f\u6211\u4eec\u7a0b\u5e8f\u5458\u9700\u8981\u53bb\u5173\u6ce8\u7684\u4e8b\u60c5\u3002\u5f53\u6211\u4eec\u53bb\u8bbe\u8ba1\u6570\u636e\u5e93\u8868\u7ed3\u6784\uff0c\u5bf9\u64cd\u4f5c\u6570\u636e\u5e93\u65f6\uff08\u5c24\u5176\u662f\u67e5\u8868\u65f6\u7684SQL\u8bed\u53e5\uff09\uff0c\u6211\u4eec\u90fd\u9700\u8981\u6ce8\u610f\u6570\u636e\u64cd\u4f5c\u7684\u6027\u80fd\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u4e0d\u4f1a\u8bb2\u8fc7\u591a\u7684SQL\u8bed\u53e5\u7684\u4f18\u5316\uff0c\u800c\u53ea\u662f\u9488\u5bf9MySQL\u8fd9\u4e00Web\u5e94\u7528\u6700\u591a\u7684\u6570\u636e\u5e93\u3002\u5e0c\u671b\u4e0b\u9762\u7684\u8fd9\u4e9b\u4f18\u5316\u6280\u5de7\u5bf9\u4f60\u6709\u7528\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">1. \u4e3a\u67e5\u8be2\u7f13\u5b58\u4f18\u5316\u4f60\u7684\u67e5\u8be2<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5927\u591a\u6570\u7684MySQL\u670d\u52a1\u5668\u90fd\u5f00\u542f\u4e86\u67e5\u8be2\u7f13\u5b58\u3002\u8fd9\u662f\u63d0\u9ad8\u6027\u6700\u6709\u6548\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u800c\u4e14\u8fd9\u662f\u88abMySQL\u7684\u6570\u636e\u5e93\u5f15\u64ce\u5904\u7406\u7684\u3002\u5f53\u6709\u5f88\u591a\u76f8\u540c\u7684\u67e5\u8be2\u88ab\u6267\u884c\u4e86\u591a\u6b21\u7684\u65f6\u5019\uff0c\u8fd9\u4e9b\u67e5\u8be2\u7ed3\u679c\u4f1a\u88ab\u653e\u5230\u4e00\u4e2a\u7f13\u5b58\u4e2d\uff0c\u8fd9\u6837\uff0c\u540e\u7eed\u7684\u76f8\u540c\u7684\u67e5\u8be2\u5c31\u4e0d\u7528\u64cd\u4f5c\u8868\u800c\u76f4\u63a5\u8bbf\u95ee\u7f13\u5b58\u7ed3\u679c\u4e86\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u8fd9\u91cc\u6700\u4e3b\u8981\u7684\u95ee\u9898\u662f\uff0c\u5bf9\u4e8e\u7a0b\u5e8f\u5458\u6765\u8bf4\uff0c\u8fd9\u4e2a\u4e8b\u60c5\u662f\u5f88\u5bb9\u6613\u88ab\u5ffd\u7565\u7684\u3002\u56e0\u4e3a\uff0c\u6211\u4eec\u67d0\u4e9b\u67e5\u8be2\u8bed\u53e5\u4f1a\u8ba9MySQL\u4e0d\u4f7f\u7528\u7f13\u5b58\u3002\u8bf7\u770b\u4e0b\u9762\u7684\u793a\u4f8b\uff1a<\/p>\n<pre class=\"language-php\"><code>\/\/ \u67e5\u8be2\u7f13\u5b58\u4e0d\u5f00\u542f\r\n$r = mysql_query(\"SELECT username FROM user WHERE signup_date &gt;= CURDATE()\");\r\n \r\n\/\/ \u5f00\u542f\u67e5\u8be2\u7f13\u5b58\r\n$today = date(\"Y-m-d\");\r\n$r = mysql_query(\"SELECT username FROM user WHERE signup_date &gt;= '$today'\");<\/code><\/pre>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4e0a\u9762\u4e24\u6761SQL\u8bed\u53e5\u7684\u5dee\u522b\u5c31\u662f CURDATE() \uff0cMySQL\u7684\u67e5\u8be2\u7f13\u5b58\u5bf9\u8fd9\u4e2a\u51fd\u6570\u4e0d\u8d77\u4f5c\u7528\u3002\u6240\u4ee5\uff0c\u50cf NOW() \u548c RAND() \u6216\u662f\u5176\u5b83\u7684\u8bf8\u5982\u6b64\u7c7b\u7684SQL\u51fd\u6570\u90fd\u4e0d\u4f1a\u5f00\u542f\u67e5\u8be2\u7f13\u5b58\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u51fd\u6570\u7684\u8fd4\u56de\u662f\u4f1a\u4e0d\u5b9a\u7684\u6613\u53d8\u7684\u3002\u6240\u4ee5\uff0c\u4f60\u6240\u9700\u8981\u7684\u5c31\u662f\u7528\u4e00\u4e2a\u53d8\u91cf\u6765\u4ee3\u66ffMySQL\u7684\u51fd\u6570\uff0c\u4ece\u800c\u5f00\u542f\u7f13\u5b58\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">2. EXPLAIN \u4f60\u7684 SELECT \u67e5\u8be2<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4f7f\u7528\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/explain.html\" target=\"_blank\" rel=\"noopener\">EXPLAIN<\/a>\u00a0\u5173\u952e\u5b57\u53ef\u4ee5\u8ba9\u4f60\u77e5\u9053MySQL\u662f\u5982\u4f55\u5904\u7406\u4f60\u7684SQL\u8bed\u53e5\u7684\u3002\u8fd9\u53ef\u4ee5\u5e2e\u4f60\u5206\u6790\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u6216\u662f\u8868\u7ed3\u6784\u7684\u6027\u80fd\u74f6\u9888\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">EXPLAIN \u7684\u67e5\u8be2\u7ed3\u679c\u8fd8\u4f1a\u544a\u8bc9\u4f60\u4f60\u7684\u7d22\u5f15\u4e3b\u952e\u88ab\u5982\u4f55\u5229\u7528\u7684\uff0c\u4f60\u7684\u6570\u636e\u8868\u662f\u5982\u4f55\u88ab\u641c\u7d22\u548c\u6392\u5e8f\u7684\u2026\u2026\u7b49\u7b49\uff0c\u7b49\u7b49\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u6311\u4e00\u4e2a\u4f60\u7684SELECT\u8bed\u53e5\uff08\u63a8\u8350\u6311\u9009\u90a3\u4e2a\u6700\u590d\u6742\u7684\uff0c\u6709\u591a\u8868\u8054\u63a5\u7684\uff09\uff0c\u628a\u5173\u952e\u5b57EXPLAIN\u52a0\u5230\u524d\u9762\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528phpmyadmin\u6765\u505a\u8fd9\u4e2a\u4e8b\u3002\u7136\u540e\uff0c\u4f60\u4f1a\u770b\u5230\u4e00\u5f20\u8868\u683c\u3002\u4e0b\u9762\u7684\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5fd8\u8bb0\u52a0\u4e0a\u4e86group_id\u7d22\u5f15\uff0c\u5e76\u4e14\u6709\u8868\u8054\u63a5\uff1a<\/p>\n<div class=\"tutorial_image\" style=\"overflow-wrap: break-word; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.djlog.cn\/wp-content\/uploads\/2021\/10\/65268-unoptimized_explain.jpg'><img class=\"lazyload lazyload-style-8\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" class=\"medium-zoom-image\" style=\"border: 0px; max-width: 100%; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;\" data-original=\"https:\/\/www.djlog.cn\/wp-content\/uploads\/2021\/10\/65268-unoptimized_explain.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" border=\"0\" \/><\/div><\/div>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5f53\u6211\u4eec\u4e3a group_id \u5b57\u6bb5\u52a0\u4e0a\u7d22\u5f15\u540e\uff1a<\/p>\n<div class=\"tutorial_image\" style=\"overflow-wrap: break-word; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.djlog.cn\/wp-content\/uploads\/2021\/10\/29f50-optimized_explain.jpg'><img class=\"lazyload lazyload-style-8\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" class=\"medium-zoom-image\" style=\"border: 0px; max-width: 100%; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;\" data-original=\"https:\/\/www.djlog.cn\/wp-content\/uploads\/2021\/10\/29f50-optimized_explain.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" border=\"0\" \/><\/div><\/div>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u524d\u4e00\u4e2a\u7ed3\u679c\u663e\u793a\u641c\u7d22\u4e86 7883 \u884c\uff0c\u800c\u540e\u4e00\u4e2a\u53ea\u662f\u641c\u7d22\u4e86\u4e24\u4e2a\u8868\u7684 9 \u548c 16 \u884c\u3002\u67e5\u770brows\u5217\u53ef\u4ee5\u8ba9\u6211\u4eec\u627e\u5230\u6f5c\u5728\u7684\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">3. \u5f53\u53ea\u8981\u4e00\u884c\u6570\u636e\u65f6\u4f7f\u7528 LIMIT 1<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5f53\u4f60\u67e5\u8be2\u8868\u7684\u6709\u4e9b\u65f6\u5019\uff0c\u4f60\u5df2\u7ecf\u77e5\u9053\u7ed3\u679c\u53ea\u4f1a\u6709\u4e00\u6761\u7ed3\u679c\uff0c\u4f46\u56e0\u4e3a\u4f60\u53ef\u80fd\u9700\u8981\u53bbfetch\u6e38\u6807\uff0c\u6216\u662f\u4f60\u4e5f\u8bb8\u4f1a\u53bb\u68c0\u67e5\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u52a0\u4e0a LIMIT 1 \u53ef\u4ee5\u589e\u52a0\u6027\u80fd\u3002\u8fd9\u6837\u4e00\u6837\uff0cMySQL\u6570\u636e\u5e93\u5f15\u64ce\u4f1a\u5728\u627e\u5230\u4e00\u6761\u6570\u636e\u540e\u505c\u6b62\u641c\u7d22\uff0c\u800c\u4e0d\u662f\u7ee7\u7eed\u5f80\u540e\u67e5\u5c11\u4e0b\u4e00\u6761\u7b26\u5408\u8bb0\u5f55\u7684\u6570\u636e\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4e0b\u9762\u7684\u793a\u4f8b\uff0c\u53ea\u662f\u4e3a\u4e86\u627e\u4e00\u4e0b\u662f\u5426\u6709\u201c\u4e2d\u56fd\u201d\u7684\u7528\u6237\uff0c\u5f88\u660e\u663e\uff0c\u540e\u9762\u7684\u4f1a\u6bd4\u524d\u9762\u7684\u66f4\u6709\u6548\u7387\u3002\uff08\u8bf7\u6ce8\u610f\uff0c\u7b2c\u4e00\u6761\u4e2d\u662fSelect *\uff0c\u7b2c\u4e8c\u6761\u662fSelect 1\uff09<\/p>\n<pre class=\"language-php\"><code>\/\/ \u6ca1\u6709\u6548\u7387\u7684\uff1a\r\n$r = mysql_query(\"SELECT * FROM user WHERE country = 'China'\");\r\nif (mysql_num_rows($r) &gt; 0) {\r\n    \/\/ ...\r\n}\r\n \r\n\/\/ \u6709\u6548\u7387\u7684\uff1a\r\n$r = mysql_query(\"SELECT 1 FROM user WHERE country = 'China' LIMIT 1\");\r\nif (mysql_num_rows($r) &gt; 0) {\r\n    \/\/ ...\r\n}<\/code><\/pre>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">4. \u4e3a\u641c\u7d22\u5b57\u6bb5\u5efa\u7d22\u5f15<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u7d22\u5f15\u5e76\u4e0d\u4e00\u5b9a\u5c31\u662f\u7ed9\u4e3b\u952e\u6216\u662f\u552f\u4e00\u7684\u5b57\u6bb5\u3002\u5982\u679c\u5728\u4f60\u7684\u8868\u4e2d\uff0c\u6709\u67d0\u4e2a\u5b57\u6bb5\u4f60\u603b\u8981\u4f1a\u7ecf\u5e38\u7528\u6765\u505a\u641c\u7d22\uff0c\u90a3\u4e48\uff0c\u8bf7\u4e3a\u5176\u5efa\u7acb\u7d22\u5f15\u5427\u3002<\/p>\n<div class=\"tutorial_image\" style=\"overflow-wrap: break-word; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.djlog.cn\/wp-content\/uploads\/2021\/10\/296ba-search_index.jpg'><img class=\"lazyload lazyload-style-8\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" class=\"medium-zoom-image\" style=\"border: 0px; max-width: 100%; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;\" data-original=\"https:\/\/www.djlog.cn\/wp-content\/uploads\/2021\/10\/296ba-search_index.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" border=\"0\" \/><\/div><\/div>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4ece\u4e0a\u56fe\u4f60\u53ef\u4ee5\u770b\u5230\u90a3\u4e2a\u641c\u7d22\u5b57\u4e32 \u201clast_name LIKE \u2018a%&#8217;\u201d\uff0c\u4e00\u4e2a\u662f\u5efa\u4e86\u7d22\u5f15\uff0c\u4e00\u4e2a\u662f\u6ca1\u6709\u7d22\u5f15\uff0c\u6027\u80fd\u5dee\u4e864\u500d\u5de6\u53f3\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u53e6\u5916\uff0c\u4f60\u5e94\u8be5\u4e5f\u9700\u8981\u77e5\u9053\u4ec0\u4e48\u6837\u7684\u641c\u7d22\u662f\u4e0d\u80fd\u4f7f\u7528\u6b63\u5e38\u7684\u7d22\u5f15\u7684\u3002\u4f8b\u5982\uff0c\u5f53\u4f60\u9700\u8981\u5728\u4e00\u7bc7\u5927\u7684\u6587\u7ae0\u4e2d\u641c\u7d22\u4e00\u4e2a\u8bcd\u65f6\uff0c\u5982\uff1a \u201cWHERE post_content LIKE \u2018%apple%&#8217;\u201d\uff0c\u7d22\u5f15\u53ef\u80fd\u662f\u6ca1\u6709\u610f\u4e49\u7684\u3002\u4f60\u53ef\u80fd\u9700\u8981\u4f7f\u7528<a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/fulltext-search.html\" target=\"_blank\" rel=\"noopener\">MySQL\u5168\u6587\u7d22\u5f15<\/a>\u00a0\u6216\u662f\u81ea\u5df1\u505a\u4e00\u4e2a\u7d22\u5f15\uff08\u6bd4\u5982\u8bf4\uff1a\u641c\u7d22\u5173\u952e\u8bcd\u6216\u662fTag\u4ec0\u4e48\u7684\uff09<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">5. \u5728Join\u8868\u7684\u65f6\u5019\u4f7f\u7528\u76f8\u5f53\u7c7b\u578b\u7684\u4f8b\uff0c\u5e76\u5c06\u5176\u7d22\u5f15<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u6709\u5f88\u591a JOIN \u67e5\u8be2\uff0c\u4f60\u5e94\u8be5\u786e\u8ba4\u4e24\u4e2a\u8868\u4e2dJoin\u7684\u5b57\u6bb5\u662f\u88ab\u5efa\u8fc7\u7d22\u5f15\u7684\u3002\u8fd9\u6837\uff0cMySQL\u5185\u90e8\u4f1a\u542f\u52a8\u4e3a\u4f60\u4f18\u5316Join\u7684SQL\u8bed\u53e5\u7684\u673a\u5236\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u800c\u4e14\uff0c\u8fd9\u4e9b\u88ab\u7528\u6765Join\u7684\u5b57\u6bb5\uff0c\u5e94\u8be5\u662f\u76f8\u540c\u7684\u7c7b\u578b\u7684\u3002\u4f8b\u5982\uff1a\u5982\u679c\u4f60\u8981\u628a DECIMAL \u5b57\u6bb5\u548c\u4e00\u4e2a INT \u5b57\u6bb5Join\u5728\u4e00\u8d77\uff0cMySQL\u5c31\u65e0\u6cd5\u4f7f\u7528\u5b83\u4eec\u7684\u7d22\u5f15\u3002\u5bf9\u4e8e\u90a3\u4e9bSTRING\u7c7b\u578b\uff0c\u8fd8\u9700\u8981\u6709\u76f8\u540c\u7684\u5b57\u7b26\u96c6\u624d\u884c\u3002\uff08\u4e24\u4e2a\u8868\u7684\u5b57\u7b26\u96c6\u6709\u53ef\u80fd\u4e0d\u4e00\u6837\uff09<\/p>\n<pre class=\"language-php\"><code>\/\/ \u5728state\u4e2d\u67e5\u627ecompany\r\n$r = mysql_query(\"SELECT company_name FROM users LEFT JOIN companies ON (users.state = companies.state) WHERE users.id = $user_id\");\r\n \r\n\/\/ \u4e24\u4e2a state \u5b57\u6bb5\u5e94\u8be5\u662f\u88ab\u5efa\u8fc7\u7d22\u5f15\u7684\uff0c\u800c\u4e14\u5e94\u8be5\u662f\u76f8\u5f53\u7684\u7c7b\u578b\uff0c\u76f8\u540c\u7684\u5b57\u7b26\u96c6\u3002<\/code><\/pre>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">6. \u5343\u4e07\u4e0d\u8981 ORDER BY RAND()<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u60f3\u6253\u4e71\u8fd4\u56de\u7684\u6570\u636e\u884c\uff1f\u968f\u673a\u6311\u4e00\u4e2a\u6570\u636e\uff1f\u771f\u4e0d\u77e5\u9053\u8c01\u53d1\u660e\u4e86\u8fd9\u79cd\u7528\u6cd5\uff0c\u4f46\u5f88\u591a\u65b0\u624b\u5f88\u559c\u6b22\u8fd9\u6837\u7528\u3002\u4f46\u4f60\u786e\u4e0d\u4e86\u89e3\u8fd9\u6837\u505a\u6709\u591a\u4e48\u53ef\u6015\u7684\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5982\u679c\u4f60\u771f\u7684\u60f3\u628a\u8fd4\u56de\u7684\u6570\u636e\u884c\u6253\u4e71\u4e86\uff0c\u4f60\u6709N\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8fbe\u5230\u8fd9\u4e2a\u76ee\u7684\u3002\u8fd9\u6837\u4f7f\u7528\u53ea\u8ba9\u4f60\u7684\u6570\u636e\u5e93\u7684\u6027\u80fd\u5448\u6307\u6570\u7ea7\u7684\u4e0b\u964d\u3002\u8fd9\u91cc\u7684\u95ee\u9898\u662f\uff1aMySQL\u4f1a\u4e0d\u5f97\u4e0d\u53bb\u6267\u884cRAND()\u51fd\u6570\uff08\u5f88\u8017CPU\u65f6\u95f4\uff09\uff0c\u800c\u4e14\u8fd9\u662f\u4e3a\u4e86\u6bcf\u4e00\u884c\u8bb0\u5f55\u53bb\u8bb0\u884c\uff0c\u7136\u540e\u518d\u5bf9\u5176\u6392\u5e8f\u3002\u5c31\u7b97\u662f\u4f60\u7528\u4e86Limit 1\u4e5f\u65e0\u6d4e\u4e8e\u4e8b\uff08\u56e0\u4e3a\u8981\u6392\u5e8f\uff09<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4e0b\u9762\u7684\u793a\u4f8b\u662f\u968f\u673a\u6311\u4e00\u6761\u8bb0\u5f55<\/p>\n<pre class=\"language-php\"><code>\/\/ \u5343\u4e07\u4e0d\u8981\u8fd9\u6837\u505a\uff1a\r\n$r = mysql_query(\"SELECT username FROM user ORDER BY RAND() LIMIT 1\");\r\n \r\n\/\/ \u8fd9\u8981\u4f1a\u66f4\u597d\uff1a\r\n$r = mysql_query(\"SELECT count(*) FROM user\");\r\n$d = mysql_fetch_row($r);\r\n$rand = mt_rand(0,$d[0] - 1);\r\n \r\n$r = mysql_query(\"SELECT username FROM user LIMIT $rand, 1\");<\/code><\/pre>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">7. \u907f\u514d SELECT *<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4ece\u6570\u636e\u5e93\u91cc\u8bfb\u51fa\u8d8a\u591a\u7684\u6570\u636e\uff0c\u90a3\u4e48\u67e5\u8be2\u5c31\u4f1a\u53d8\u5f97\u8d8a\u6162\u3002\u5e76\u4e14\uff0c\u5982\u679c\u4f60\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u548cWEB\u670d\u52a1\u5668\u662f\u4e24\u53f0\u72ec\u7acb\u7684\u670d\u52a1\u5668\u7684\u8bdd\uff0c\u8fd9\u8fd8\u4f1a\u589e\u52a0\u7f51\u7edc\u4f20\u8f93\u7684\u8d1f\u8f7d\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u6240\u4ee5\uff0c\u4f60\u5e94\u8be5\u517b\u6210\u4e00\u4e2a\u9700\u8981\u4ec0\u4e48\u5c31\u53d6\u4ec0\u4e48\u7684\u597d\u7684\u4e60\u60ef\u3002<\/p>\n<pre class=\"language-php\"><code>\/\/ \u4e0d\u63a8\u8350\r\n$r = mysql_query(\"SELECT * FROM user WHERE user_id = 1\");\r\n$d = mysql_fetch_assoc($r);\r\necho \"Welcome {$d['username']}\";\r\n \r\n\/\/ \u63a8\u8350\r\n$r = mysql_query(\"SELECT username FROM user WHERE user_id = 1\");\r\n$d = mysql_fetch_assoc($r);\r\necho \"Welcome {$d['username']}\";<\/code><\/pre>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">8. \u6c38\u8fdc\u4e3a\u6bcf\u5f20\u8868\u8bbe\u7f6e\u4e00\u4e2aID<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u6211\u4eec\u5e94\u8be5\u4e3a\u6570\u636e\u5e93\u91cc\u7684\u6bcf\u5f20\u8868\u90fd\u8bbe\u7f6e\u4e00\u4e2aID\u505a\u4e3a\u5176\u4e3b\u952e\uff0c\u800c\u4e14\u6700\u597d\u7684\u662f\u4e00\u4e2aINT\u578b\u7684\uff08\u63a8\u8350\u4f7f\u7528UNSIGNED\uff09\uff0c\u5e76\u8bbe\u7f6e\u4e0a\u81ea\u52a8\u589e\u52a0\u7684AUTO_INCREMENT\u6807\u5fd7\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5c31\u7b97\u662f\u4f60 users \u8868\u6709\u4e00\u4e2a\u4e3b\u952e\u53eb \u201cemail\u201d\u7684\u5b57\u6bb5\uff0c\u4f60\u4e5f\u522b\u8ba9\u5b83\u6210\u4e3a\u4e3b\u952e\u3002\u4f7f\u7528 VARCHAR \u7c7b\u578b\u6765\u5f53\u4e3b\u952e\u4f1a\u4f7f\u7528\u5f97\u6027\u80fd\u4e0b\u964d\u3002\u53e6\u5916\uff0c\u5728\u4f60\u7684\u7a0b\u5e8f\u4e2d\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528\u8868\u7684ID\u6765\u6784\u9020\u4f60\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u800c\u4e14\uff0c\u5728MySQL\u6570\u636e\u5f15\u64ce\u4e0b\uff0c\u8fd8\u6709\u4e00\u4e9b\u64cd\u4f5c\u9700\u8981\u4f7f\u7528\u4e3b\u952e\uff0c\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e3b\u952e\u7684\u6027\u80fd\u548c\u8bbe\u7f6e\u53d8\u5f97\u975e\u5e38\u91cd\u8981\uff0c\u6bd4\u5982\uff0c\u96c6\u7fa4\uff0c\u5206\u533a\u2026\u2026<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5728\u8fd9\u91cc\uff0c\u53ea\u6709\u4e00\u4e2a\u60c5\u51b5\u662f\u4f8b\u5916\uff0c\u90a3\u5c31\u662f\u201c\u5173\u8054\u8868\u201d\u7684\u201c\u5916\u952e\u201d\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\uff0c\u901a\u8fc7\u82e5\u5e72\u4e2a\u522b\u7684\u8868\u7684\u4e3b\u952e\u6784\u6210\u3002\u6211\u4eec\u628a\u8fd9\u4e2a\u60c5\u51b5\u53eb\u505a\u201c\u5916\u952e\u201d\u3002\u6bd4\u5982\uff1a\u6709\u4e00\u4e2a\u201c\u5b66\u751f\u8868\u201d\u6709\u5b66\u751f\u7684ID\uff0c\u6709\u4e00\u4e2a\u201c\u8bfe\u7a0b\u8868\u201d\u6709\u8bfe\u7a0bID\uff0c\u90a3\u4e48\uff0c\u201c\u6210\u7ee9\u8868\u201d\u5c31\u662f\u201c\u5173\u8054\u8868\u201d\u4e86\uff0c\u5176\u5173\u8054\u4e86\u5b66\u751f\u8868\u548c\u8bfe\u7a0b\u8868\uff0c\u5728\u6210\u7ee9\u8868\u4e2d\uff0c\u5b66\u751fID\u548c\u8bfe\u7a0bID\u53eb\u201c\u5916\u952e\u201d\u5176\u5171\u540c\u7ec4\u6210\u4e3b\u952e\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">9. \u4f7f\u7528 ENUM \u800c\u4e0d\u662f VARCHAR<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/enum.html\" target=\"_blank\" rel=\"noopener\">ENUM<\/a>\u00a0\u7c7b\u578b\u662f\u975e\u5e38\u5feb\u548c\u7d27\u51d1\u7684\u3002\u5728\u5b9e\u9645\u4e0a\uff0c\u5176\u4fdd\u5b58\u7684\u662f TINYINT\uff0c\u4f46\u5176\u5916\u8868\u4e0a\u663e\u793a\u4e3a\u5b57\u7b26\u4e32\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u7528\u8fd9\u4e2a\u5b57\u6bb5\u6765\u505a\u4e00\u4e9b\u9009\u9879\u5217\u8868\u53d8\u5f97\u76f8\u5f53\u7684\u5b8c\u7f8e\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6bd4\u5982\u201c\u6027\u522b\u201d\uff0c\u201c\u56fd\u5bb6\u201d\uff0c\u201c\u6c11\u65cf\u201d\uff0c\u201c\u72b6\u6001\u201d\u6216\u201c\u90e8\u95e8\u201d\uff0c\u4f60\u77e5\u9053\u8fd9\u4e9b\u5b57\u6bb5\u7684\u53d6\u503c\u662f\u6709\u9650\u800c\u4e14\u56fa\u5b9a\u7684\uff0c\u90a3\u4e48\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528 ENUM \u800c\u4e0d\u662f VARCHAR\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">MySQL\u4e5f\u6709\u4e00\u4e2a\u201c\u5efa\u8bae\u201d\uff08\u89c1\u7b2c\u5341\u6761\uff09\u544a\u8bc9\u4f60\u600e\u4e48\u53bb\u91cd\u65b0\u7ec4\u7ec7\u4f60\u7684\u8868\u7ed3\u6784\u3002\u5f53\u4f60\u6709\u4e00\u4e2a VARCHAR \u5b57\u6bb5\u65f6\uff0c\u8fd9\u4e2a\u5efa\u8bae\u4f1a\u544a\u8bc9\u4f60\u628a\u5176\u6539\u6210 ENUM \u7c7b\u578b\u3002\u4f7f\u7528 PROCEDURE ANALYSE() \u4f60\u53ef\u4ee5\u5f97\u5230\u76f8\u5173\u7684\u5efa\u8bae\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">10. \u4ece PROCEDURE ANALYSE() \u53d6\u5f97\u5efa\u8bae<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/procedure-analyse.html\" target=\"_blank\" rel=\"noopener\">PROCEDURE ANALYSE()<\/a>\u00a0\u4f1a\u8ba9 MySQL \u5e2e\u4f60\u53bb\u5206\u6790\u4f60\u7684\u5b57\u6bb5\u548c\u5176\u5b9e\u9645\u7684\u6570\u636e\uff0c\u5e76\u4f1a\u7ed9\u4f60\u4e00\u4e9b\u6709\u7528\u7684\u5efa\u8bae\u3002\u53ea\u6709\u8868\u4e2d\u6709\u5b9e\u9645\u7684\u6570\u636e\uff0c\u8fd9\u4e9b\u5efa\u8bae\u624d\u4f1a\u53d8\u5f97\u6709\u7528\uff0c\u56e0\u4e3a\u8981\u505a\u4e00\u4e9b\u5927\u7684\u51b3\u5b9a\u662f\u9700\u8981\u6709\u6570\u636e\u4f5c\u4e3a\u57fa\u7840\u7684\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u521b\u5efa\u4e86\u4e00\u4e2a INT \u5b57\u6bb5\u4f5c\u4e3a\u4f60\u7684\u4e3b\u952e\uff0c\u7136\u800c\u5e76\u6ca1\u6709\u592a\u591a\u7684\u6570\u636e\uff0c\u90a3\u4e48\uff0cPROCEDURE ANALYSE()\u4f1a\u5efa\u8bae\u4f60\u628a\u8fd9\u4e2a\u5b57\u6bb5\u7684\u7c7b\u578b\u6539\u6210 MEDIUMINT \u3002\u6216\u662f\u4f60\u4f7f\u7528\u4e86\u4e00\u4e2a VARCHAR \u5b57\u6bb5\uff0c\u56e0\u4e3a\u6570\u636e\u4e0d\u591a\uff0c\u4f60\u53ef\u80fd\u4f1a\u5f97\u5230\u4e00\u4e2a\u8ba9\u4f60\u628a\u5b83\u6539\u6210 ENUM \u7684\u5efa\u8bae\u3002\u8fd9\u4e9b\u5efa\u8bae\uff0c\u90fd\u662f\u53ef\u80fd\u56e0\u4e3a\u6570\u636e\u4e0d\u591f\u591a\uff0c\u6240\u4ee5\u51b3\u7b56\u505a\u5f97\u5c31\u4e0d\u591f\u51c6\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5728phpmyadmin\u91cc\uff0c\u4f60\u53ef\u4ee5\u5728\u67e5\u770b\u8868\u65f6\uff0c\u70b9\u51fb \u201cPropose table structure\u201d \u6765\u67e5\u770b\u8fd9\u4e9b\u5efa\u8bae<\/p>\n<div class=\"tutorial_image\" style=\"overflow-wrap: break-word; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.djlog.cn\/wp-content\/uploads\/2021\/10\/7b26a-suggestions.jpg'><img class=\"lazyload lazyload-style-8\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" class=\"medium-zoom-image\" style=\"border: 0px; max-width: 100%; cursor: zoom-in; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important; height: auto;\" data-original=\"https:\/\/www.djlog.cn\/wp-content\/uploads\/2021\/10\/7b26a-suggestions.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" border=\"0\" \/><\/div><\/div>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4e00\u5b9a\u8981\u6ce8\u610f\uff0c\u8fd9\u4e9b\u53ea\u662f\u5efa\u8bae\uff0c\u53ea\u6709\u5f53\u4f60\u7684\u8868\u91cc\u7684\u6570\u636e\u8d8a\u6765\u8d8a\u591a\u65f6\uff0c\u8fd9\u4e9b\u5efa\u8bae\u624d\u4f1a\u53d8\u5f97\u51c6\u786e\u3002\u4e00\u5b9a\u8981\u8bb0\u4f4f\uff0c\u4f60\u624d\u662f\u6700\u7ec8\u505a\u51b3\u5b9a\u7684\u4eba\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">11. \u5c3d\u53ef\u80fd\u7684\u4f7f\u7528 NOT NULL<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u9664\u975e\u4f60\u6709\u4e00\u4e2a\u5f88\u7279\u522b\u7684\u539f\u56e0\u53bb\u4f7f\u7528 NULL \u503c\uff0c\u4f60\u5e94\u8be5\u603b\u662f\u8ba9\u4f60\u7684\u5b57\u6bb5\u4fdd\u6301 NOT NULL\u3002\u8fd9\u770b\u8d77\u6765\u597d\u50cf\u6709\u70b9\u4e89\u8bae\uff0c\u8bf7\u5f80\u4e0b\u770b\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u9996\u5148\uff0c\u95ee\u95ee\u4f60\u81ea\u5df1\u201cEmpty\u201d\u548c\u201cNULL\u201d\u6709\u591a\u5927\u7684\u533a\u522b\uff08\u5982\u679c\u662fINT\uff0c\u90a3\u5c31\u662f0\u548cNULL\uff09\uff1f\u5982\u679c\u4f60\u89c9\u5f97\u5b83\u4eec\u4e4b\u95f4\u6ca1\u6709\u4ec0\u4e48\u533a\u522b\uff0c\u90a3\u4e48\u4f60\u5c31\u4e0d\u8981\u4f7f\u7528NULL\u3002\uff08\u4f60\u77e5\u9053\u5417\uff1f\u5728 Oracle \u91cc\uff0cNULL \u548c Empty \u7684\u5b57\u7b26\u4e32\u662f\u4e00\u6837\u7684\uff01)<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4e0d\u8981\u4ee5\u4e3a NULL \u4e0d\u9700\u8981\u7a7a\u95f4\uff0c\u5176\u9700\u8981\u989d\u5916\u7684\u7a7a\u95f4\uff0c\u5e76\u4e14\uff0c\u5728\u4f60\u8fdb\u884c\u6bd4\u8f83\u7684\u65f6\u5019\uff0c\u4f60\u7684\u7a0b\u5e8f\u4f1a\u66f4\u590d\u6742\u3002 \u5f53\u7136\uff0c\u8fd9\u91cc\u5e76\u4e0d\u662f\u8bf4\u4f60\u5c31\u4e0d\u80fd\u4f7f\u7528NULL\u4e86\uff0c\u73b0\u5b9e\u60c5\u51b5\u662f\u5f88\u590d\u6742\u7684\uff0c\u4f9d\u7136\u4f1a\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u9700\u8981\u4f7f\u7528NULL\u503c\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4e0b\u9762\u6458\u81eaMySQL\u81ea\u5df1\u7684\u6587\u6863\uff1a<\/p>\n<blockquote style=\"background: none #ffffff; border-top: none; border-right: none; border-bottom: none; border-left-width: 3px; border-left-color: #e2dfdf; border-image: initial; padding: 5px 10px; margin: 10px 0px; color: #555555; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;\">\n<p style=\"margin: 10px auto;\">\u201cNULL columns require additional space in the row to record whether their values are NULL. For MyISAM tables, each NULL column takes one bit extra, rounded up to the nearest byte.\u201d<\/p>\n<\/blockquote>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">12. Prepared Statements<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">Prepared Statements\u5f88\u50cf\u5b58\u50a8\u8fc7\u7a0b\uff0c\u662f\u4e00\u79cd\u8fd0\u884c\u5728\u540e\u53f0\u7684SQL\u8bed\u53e5\u96c6\u5408\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u4f7f\u7528 prepared statements \u83b7\u5f97\u5f88\u591a\u597d\u5904\uff0c\u65e0\u8bba\u662f\u6027\u80fd\u95ee\u9898\u8fd8\u662f\u5b89\u5168\u95ee\u9898\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">Prepared Statements \u53ef\u4ee5\u68c0\u67e5\u4e00\u4e9b\u4f60\u7ed1\u5b9a\u597d\u7684\u53d8\u91cf\uff0c\u8fd9\u6837\u53ef\u4ee5\u4fdd\u62a4\u4f60\u7684\u7a0b\u5e8f\u4e0d\u4f1a\u53d7\u5230\u201cSQL\u6ce8\u5165\u5f0f\u201d\u653b\u51fb\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u624b\u52a8\u5730\u68c0\u67e5\u4f60\u7684\u8fd9\u4e9b\u53d8\u91cf\uff0c\u7136\u800c\uff0c\u624b\u52a8\u7684\u68c0\u67e5\u5bb9\u6613\u51fa\u95ee\u9898\uff0c\u800c\u4e14\u5f88\u7ecf\u5e38\u4f1a\u88ab\u7a0b\u5e8f\u5458\u5fd8\u4e86\u3002\u5f53\u6211\u4eec\u4f7f\u7528\u4e00\u4e9bframework\u6216\u662fORM\u7684\u65f6\u5019\uff0c\u8fd9\u6837\u7684\u95ee\u9898\u4f1a\u597d\u4e00\u4e9b\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5728\u6027\u80fd\u65b9\u9762\uff0c\u5f53\u4e00\u4e2a\u76f8\u540c\u7684\u67e5\u8be2\u88ab\u4f7f\u7528\u591a\u6b21\u7684\u65f6\u5019\uff0c\u8fd9\u4f1a\u4e3a\u4f60\u5e26\u6765\u53ef\u89c2\u7684\u6027\u80fd\u4f18\u52bf\u3002\u4f60\u53ef\u4ee5\u7ed9\u8fd9\u4e9bPrepared Statements\u5b9a\u4e49\u4e00\u4e9b\u53c2\u6570\uff0c\u800cMySQL\u53ea\u4f1a\u89e3\u6790\u4e00\u6b21\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u867d\u7136\u6700\u65b0\u7248\u672c\u7684MySQL\u5728\u4f20\u8f93Prepared Statements\u662f\u4f7f\u7528\u4e8c\u8fdb\u5236\u5f62\u52bf\uff0c\u6240\u4ee5\u8fd9\u4f1a\u4f7f\u5f97\u7f51\u7edc\u4f20\u8f93\u975e\u5e38\u6709\u6548\u7387\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5f53\u7136\uff0c\u4e5f\u6709\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u907f\u514d\u4f7f\u7528Prepared Statements\uff0c\u56e0\u4e3a\u5176\u4e0d\u652f\u6301\u67e5\u8be2\u7f13\u5b58\u3002\u4f46\u636e\u8bf4\u7248\u672c5.1\u540e\u652f\u6301\u4e86\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5728PHP\u4e2d\u8981\u4f7f\u7528prepared statements\uff0c\u4f60\u53ef\u4ee5\u67e5\u770b\u5176\u4f7f\u7528\u624b\u518c\uff1a<a style=\"color: #78afd3;\" href=\"http:\/\/php.net\/manual\/en\/book.mysqli.php\" target=\"_blank\" rel=\"noopener\">mysqli \u6269\u5c55<\/a>\u00a0\u6216\u662f\u4f7f\u7528\u6570\u636e\u5e93\u62bd\u8c61\u5c42\uff0c\u5982\uff1a\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/us.php.net\/manual\/en\/book.pdo.php\" target=\"_blank\" rel=\"noopener\">PDO<\/a>.<\/p>\n<pre class=\"language-php\"><code>\/\/ \u521b\u5efa prepared statement\r\nif ($stmt = $mysqli-&gt;prepare(\"SELECT username FROM user WHERE state=?\")) {\r\n \r\n    \/\/ \u7ed1\u5b9a\u53c2\u6570\r\n    $stmt-&gt;bind_param(\"s\", $state);\r\n \r\n    \/\/ \u6267\u884c\r\n    $stmt-&gt;execute();\r\n \r\n    \/\/ \u7ed1\u5b9a\u7ed3\u679c\r\n    $stmt-&gt;bind_result($username);\r\n \r\n    \/\/ \u79fb\u52a8\u6e38\u6807\r\n    $stmt-&gt;fetch();\r\n \r\n    printf(\"%s is from %s\\n\", $username, $state);\r\n \r\n    $stmt-&gt;close();\r\n}<\/code><\/pre>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">13. \u65e0\u7f13\u51b2\u7684\u67e5\u8be2<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u6b63\u5e38\u7684\u60c5\u51b5\u4e0b\uff0c\u5f53\u4f60\u5728\u5f53\u4f60\u5728\u4f60\u7684\u811a\u672c\u4e2d\u6267\u884c\u4e00\u4e2aSQL\u8bed\u53e5\u7684\u65f6\u5019\uff0c\u4f60\u7684\u7a0b\u5e8f\u4f1a\u505c\u5728\u90a3\u91cc\u76f4\u5230\u6ca1\u8fd9\u4e2aSQL\u8bed\u53e5\u8fd4\u56de\uff0c\u7136\u540e\u4f60\u7684\u7a0b\u5e8f\u518d\u5f80\u4e0b\u7ee7\u7eed\u6267\u884c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u65e0\u7f13\u51b2\u67e5\u8be2\u6765\u6539\u53d8\u8fd9\u4e2a\u884c\u4e3a\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5173\u4e8e\u8fd9\u4e2a\u4e8b\u60c5\uff0c\u5728PHP\u7684\u6587\u6863\u4e2d\u6709\u4e00\u4e2a\u975e\u5e38\u4e0d\u9519\u7684\u8bf4\u660e\uff1a<a style=\"color: #78afd3;\" href=\"http:\/\/php.net\/manual\/en\/function.mysql-unbuffered-query.php\" target=\"_blank\" rel=\"noopener\">mysql_unbuffered_query()<\/a>\u00a0\u51fd\u6570\uff1a<\/p>\n<blockquote style=\"background: none #ffffff; border-top: none; border-right: none; border-bottom: none; border-left-width: 3px; border-left-color: #e2dfdf; border-image: initial; padding: 5px 10px; margin: 10px 0px; color: #555555; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;\">\n<p style=\"margin: 10px auto;\">\u201cmysql_unbuffered_query() sends the SQL query query to MySQL without automatically fetching and buffering the result rows as mysql_query() does. This saves a considerable amount of memory with SQL queries that produce large result sets, and you can start working on the result set immediately after the first row has been retrieved as you don\u2019t have to wait until the complete SQL query has been performed.\u201d<\/p>\n<\/blockquote>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4e0a\u9762\u90a3\u53e5\u8bdd\u7ffb\u8bd1\u8fc7\u6765\u662f\u8bf4\uff0cmysql_unbuffered_query() \u53d1\u9001\u4e00\u4e2aSQL\u8bed\u53e5\u5230MySQL\u800c\u5e76\u4e0d\u50cfmysql_query()\u4e00\u6837\u53bb\u81ea\u52a8fethch\u548c\u7f13\u5b58\u7ed3\u679c\u3002\u8fd9\u4f1a\u76f8\u5f53\u8282\u7ea6\u5f88\u591a\u53ef\u89c2\u7684\u5185\u5b58\uff0c\u5c24\u5176\u662f\u90a3\u4e9b\u4f1a\u4ea7\u751f\u5927\u91cf\u7ed3\u679c\u7684\u67e5\u8be2\u8bed\u53e5\uff0c\u5e76\u4e14\uff0c\u4f60\u4e0d\u9700\u8981\u7b49\u5230\u6240\u6709\u7684\u7ed3\u679c\u90fd\u8fd4\u56de\uff0c\u53ea\u9700\u8981\u7b2c\u4e00\u884c\u6570\u636e\u8fd4\u56de\u7684\u65f6\u5019\uff0c\u4f60\u5c31\u53ef\u4ee5\u5f00\u59cb\u9a6c\u4e0a\u5f00\u59cb\u5de5\u4f5c\u4e8e\u67e5\u8be2\u7ed3\u679c\u4e86\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u7136\u800c\uff0c\u8fd9\u4f1a\u6709\u4e00\u4e9b\u9650\u5236\u3002\u56e0\u4e3a\u4f60\u8981\u4e48\u628a\u6240\u6709\u884c\u90fd\u8bfb\u8d70\uff0c\u6216\u662f\u4f60\u8981\u5728\u8fdb\u884c\u4e0b\u4e00\u6b21\u7684\u67e5\u8be2\u524d\u8c03\u7528\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/us2.php.net\/manual\/en\/function.mysql-free-result.php\" target=\"_blank\" rel=\"noopener\">mysql_free_result()<\/a>\u00a0\u6e05\u9664\u7ed3\u679c\u3002\u800c\u4e14\uff0c<a style=\"color: #78afd3;\" href=\"http:\/\/us2.php.net\/manual\/en\/function.mysql-num-rows.php\" target=\"_blank\" rel=\"noopener\">mysql_num_rows()<\/a>\u00a0\u6216\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/us2.php.net\/manual\/en\/function.mysql-data-seek.php\" target=\"_blank\" rel=\"noopener\">mysql_data_seek()<\/a>\u00a0\u5c06\u65e0\u6cd5\u4f7f\u7528\u3002\u6240\u4ee5\uff0c\u662f\u5426\u4f7f\u7528\u65e0\u7f13\u51b2\u7684\u67e5\u8be2\u4f60\u9700\u8981\u4ed4\u7ec6\u8003\u8651\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">14. \u628aIP\u5730\u5740\u5b58\u6210 UNSIGNED INT<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5f88\u591a\u7a0b\u5e8f\u5458\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a VARCHAR(15) \u5b57\u6bb5\u6765\u5b58\u653e\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684IP\u800c\u4e0d\u662f\u6574\u5f62\u7684IP\u3002\u5982\u679c\u4f60\u7528\u6574\u5f62\u6765\u5b58\u653e\uff0c\u53ea\u9700\u89814\u4e2a\u5b57\u8282\uff0c\u5e76\u4e14\u4f60\u53ef\u4ee5\u6709\u5b9a\u957f\u7684\u5b57\u6bb5\u3002\u800c\u4e14\uff0c\u8fd9\u4f1a\u4e3a\u4f60\u5e26\u6765\u67e5\u8be2\u4e0a\u7684\u4f18\u52bf\uff0c\u5c24\u5176\u662f\u5f53\u4f60\u9700\u8981\u4f7f\u7528\u8fd9\u6837\u7684WHERE\u6761\u4ef6\uff1aIP between ip1 and ip2\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u6211\u4eec\u5fc5\u9700\u8981\u4f7f\u7528UNSIGNED INT\uff0c\u56e0\u4e3a IP\u5730\u5740\u4f1a\u4f7f\u7528\u6574\u4e2a32\u4f4d\u7684\u65e0\u7b26\u53f7\u6574\u5f62\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u800c\u4f60\u7684\u67e5\u8be2\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/miscellaneous-functions.html#function_inet-aton\" target=\"_blank\" rel=\"noopener\">INET_ATON()<\/a>\u00a0\u6765\u628a\u4e00\u4e2a\u5b57\u7b26\u4e32IP\u8f6c\u6210\u4e00\u4e2a\u6574\u5f62\uff0c\u5e76\u4f7f\u7528\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/miscellaneous-functions.html#function_inet-ntoa\" target=\"_blank\" rel=\"noopener\">INET_NTOA()<\/a>\u00a0\u628a\u4e00\u4e2a\u6574\u5f62\u8f6c\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32IP\u3002\u5728PHP\u4e2d\uff0c\u4e5f\u6709\u8fd9\u6837\u7684\u51fd\u6570\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/php.net\/manual\/en\/function.ip2long.php\" target=\"_blank\" rel=\"noopener\">ip2long()<\/a>\u00a0\u548c\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/us.php.net\/manual\/en\/function.long2ip.php\" target=\"_blank\" rel=\"noopener\">long2ip()<\/a>\u3002<\/p>\n<pre class=\"language-php\"><code>$r = \"UPDATE users SET ip = INET_ATON('{$_SERVER['REMOTE_ADDR']}') WHERE user_id = $user_id\";<\/code><\/pre>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">15. \u56fa\u5b9a\u957f\u5ea6\u7684\u8868\u4f1a\u66f4\u5feb<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5982\u679c\u8868\u4e2d\u7684\u6240\u6709\u5b57\u6bb5\u90fd\u662f\u201c\u56fa\u5b9a\u957f\u5ea6\u201d\u7684\uff0c\u6574\u4e2a\u8868\u4f1a\u88ab\u8ba4\u4e3a\u662f\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/static-format.html\" target=\"_blank\" rel=\"noopener\">\u201cstatic\u201d \u6216 \u201cfixed-length\u201d<\/a>\u3002 \u4f8b\u5982\uff0c\u8868\u4e2d\u6ca1\u6709\u5982\u4e0b\u7c7b\u578b\u7684\u5b57\u6bb5\uff1a VARCHAR\uff0cTEXT\uff0cBLOB\u3002\u53ea\u8981\u4f60\u5305\u62ec\u4e86\u5176\u4e2d\u4e00\u4e2a\u8fd9\u4e9b\u5b57\u6bb5\uff0c\u90a3\u4e48\u8fd9\u4e2a\u8868\u5c31\u4e0d\u662f\u201c\u56fa\u5b9a\u957f\u5ea6\u9759\u6001\u8868\u201d\u4e86\uff0c\u8fd9\u6837\uff0cMySQL \u5f15\u64ce\u4f1a\u7528\u53e6\u4e00\u79cd\u65b9\u6cd5\u6765\u5904\u7406\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u56fa\u5b9a\u957f\u5ea6\u7684\u8868\u4f1a\u63d0\u9ad8\u6027\u80fd\uff0c\u56e0\u4e3aMySQL\u641c\u5bfb\u5f97\u4f1a\u66f4\u5feb\u4e00\u4e9b\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u56fa\u5b9a\u7684\u957f\u5ea6\u662f\u5f88\u5bb9\u6613\u8ba1\u7b97\u4e0b\u4e00\u4e2a\u6570\u636e\u7684\u504f\u79fb\u91cf\u7684\uff0c\u6240\u4ee5\u8bfb\u53d6\u7684\u81ea\u7136\u4e5f\u4f1a\u5f88\u5feb\u3002\u800c\u5982\u679c\u5b57\u6bb5\u4e0d\u662f\u5b9a\u957f\u7684\uff0c\u90a3\u4e48\uff0c\u6bcf\u4e00\u6b21\u8981\u627e\u4e0b\u4e00\u6761\u7684\u8bdd\uff0c\u9700\u8981\u7a0b\u5e8f\u627e\u5230\u4e3b\u952e\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5e76\u4e14\uff0c\u56fa\u5b9a\u957f\u5ea6\u7684\u8868\u4e5f\u66f4\u5bb9\u6613\u88ab\u7f13\u5b58\u548c\u91cd\u5efa\u3002\u4e0d\u8fc7\uff0c\u552f\u4e00\u7684\u526f\u4f5c\u7528\u662f\uff0c\u56fa\u5b9a\u957f\u5ea6\u7684\u5b57\u6bb5\u4f1a\u6d6a\u8d39\u4e00\u4e9b\u7a7a\u95f4\uff0c\u56e0\u4e3a\u5b9a\u957f\u7684\u5b57\u6bb5\u65e0\u8bba\u4f60\u7528\u4e0d\u7528\uff0c\u4ed6\u90fd\u662f\u8981\u5206\u914d\u90a3\u4e48\u591a\u7684\u7a7a\u95f4\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4f7f\u7528\u201c\u5782\u76f4\u5206\u5272\u201d\u6280\u672f\uff08\u89c1\u4e0b\u4e00\u6761\uff09\uff0c\u4f60\u53ef\u4ee5\u5206\u5272\u4f60\u7684\u8868\u6210\u4e3a\u4e24\u4e2a\u4e00\u4e2a\u662f\u5b9a\u957f\u7684\uff0c\u4e00\u4e2a\u5219\u662f\u4e0d\u5b9a\u957f\u7684\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">16. \u5782\u76f4\u5206\u5272<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u201c\u5782\u76f4\u5206\u5272\u201d\u662f\u4e00\u79cd\u628a\u6570\u636e\u5e93\u4e2d\u7684\u8868\u6309\u5217\u53d8\u6210\u51e0\u5f20\u8868\u7684\u65b9\u6cd5\uff0c\u8fd9\u6837\u53ef\u4ee5\u964d\u4f4e\u8868\u7684\u590d\u6742\u5ea6\u548c\u5b57\u6bb5\u7684\u6570\u76ee\uff0c\u4ece\u800c\u8fbe\u5230\u4f18\u5316\u7684\u76ee\u7684\u3002\uff08\u4ee5\u524d\uff0c\u5728\u94f6\u884c\u505a\u8fc7\u9879\u76ee\uff0c\u89c1\u8fc7\u4e00\u5f20\u8868\u6709100\u591a\u4e2a\u5b57\u6bb5\uff0c\u5f88\u6050\u6016\uff09<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><strong>\u793a\u4f8b\u4e00<\/strong>\uff1a\u5728Users\u8868\u4e2d\u6709\u4e00\u4e2a\u5b57\u6bb5\u662f\u5bb6\u5ead\u5730\u5740\uff0c\u8fd9\u4e2a\u5b57\u6bb5\u662f\u53ef\u9009\u5b57\u6bb5\uff0c\u76f8\u6bd4\u8d77\uff0c\u800c\u4e14\u4f60\u5728\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u65f6\u5019\u9664\u4e86\u4e2a\u4eba\u4fe1\u606f\u5916\uff0c\u4f60\u5e76\u4e0d\u9700\u8981\u7ecf\u5e38\u8bfb\u53d6\u6216\u662f\u6539\u5199\u8fd9\u4e2a\u5b57\u6bb5\u3002\u90a3\u4e48\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u628a\u4ed6\u653e\u5230\u53e6\u5916\u4e00\u5f20\u8868\u4e2d\u5462\uff1f \u8fd9\u6837\u4f1a\u8ba9\u4f60\u7684\u8868\u6709\u66f4\u597d\u7684\u6027\u80fd\uff0c\u5927\u5bb6\u60f3\u60f3\u662f\u4e0d\u662f\uff0c\u5927\u91cf\u7684\u65f6\u5019\uff0c\u6211\u5bf9\u4e8e\u7528\u6237\u8868\u6765\u8bf4\uff0c\u53ea\u6709\u7528\u6237ID\uff0c\u7528\u6237\u540d\uff0c\u53e3\u4ee4\uff0c\u7528\u6237\u89d2\u8272\u7b49\u4f1a\u88ab\u7ecf\u5e38\u4f7f\u7528\u3002\u5c0f\u4e00\u70b9\u7684\u8868\u603b\u662f\u4f1a\u6709\u597d\u7684\u6027\u80fd\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><strong>\u793a\u4f8b\u4e8c<\/strong>\uff1a \u4f60\u6709\u4e00\u4e2a\u53eb \u201clast_login\u201d \u7684\u5b57\u6bb5\uff0c\u5b83\u4f1a\u5728\u6bcf\u6b21\u7528\u6237\u767b\u5f55\u65f6\u88ab\u66f4\u65b0\u3002\u4f46\u662f\uff0c\u6bcf\u6b21\u66f4\u65b0\u65f6\u4f1a\u5bfc\u81f4\u8be5\u8868\u7684\u67e5\u8be2\u7f13\u5b58\u88ab\u6e05\u7a7a\u3002\u6240\u4ee5\uff0c\u4f60\u53ef\u4ee5\u628a\u8fd9\u4e2a\u5b57\u6bb5\u653e\u5230\u53e6\u4e00\u4e2a\u8868\u4e2d\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5f71\u54cd\u4f60\u5bf9\u7528\u6237ID\uff0c\u7528\u6237\u540d\uff0c\u7528\u6237\u89d2\u8272\u7684\u4e0d\u505c\u5730\u8bfb\u53d6\u4e86\uff0c\u56e0\u4e3a\u67e5\u8be2\u7f13\u5b58\u4f1a\u5e2e\u4f60\u589e\u52a0\u5f88\u591a\u6027\u80fd\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u53e6\u5916\uff0c\u4f60\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e9b\u88ab\u5206\u51fa\u53bb\u7684\u5b57\u6bb5\u6240\u5f62\u6210\u7684\u8868\uff0c\u4f60\u4e0d\u4f1a\u7ecf\u5e38\u6027\u5730\u53bbJoin\u4ed6\u4eec\uff0c\u4e0d\u7136\u7684\u8bdd\uff0c\u8fd9\u6837\u7684\u6027\u80fd\u4f1a\u6bd4\u4e0d\u5206\u5272\u65f6\u8fd8\u8981\u5dee\uff0c\u800c\u4e14\uff0c\u4f1a\u662f\u6781\u6570\u7ea7\u7684\u4e0b\u964d\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">17. \u62c6\u5206\u5927\u7684 DELETE \u6216 INSERT \u8bed\u53e5<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5982\u679c\u4f60\u9700\u8981\u5728\u4e00\u4e2a\u5728\u7ebf\u7684\u7f51\u7ad9\u4e0a\u53bb\u6267\u884c\u4e00\u4e2a\u5927\u7684 DELETE \u6216 INSERT \u67e5\u8be2\uff0c\u4f60\u9700\u8981\u975e\u5e38\u5c0f\u5fc3\uff0c\u8981\u907f\u514d\u4f60\u7684\u64cd\u4f5c\u8ba9\u4f60\u7684\u6574\u4e2a\u7f51\u7ad9\u505c\u6b62\u76f8\u5e94\u3002\u56e0\u4e3a\u8fd9\u4e24\u4e2a\u64cd\u4f5c\u662f\u4f1a\u9501\u8868\u7684\uff0c\u8868\u4e00\u9501\u4f4f\u4e86\uff0c\u522b\u7684\u64cd\u4f5c\u90fd\u8fdb\u4e0d\u6765\u4e86\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">Apache \u4f1a\u6709\u5f88\u591a\u7684\u5b50\u8fdb\u7a0b\u6216\u7ebf\u7a0b\u3002\u6240\u4ee5\uff0c\u5176\u5de5\u4f5c\u8d77\u6765\u76f8\u5f53\u6709\u6548\u7387\uff0c\u800c\u6211\u4eec\u7684\u670d\u52a1\u5668\u4e5f\u4e0d\u5e0c\u671b\u6709\u592a\u591a\u7684\u5b50\u8fdb\u7a0b\uff0c\u7ebf\u7a0b\u548c\u6570\u636e\u5e93\u94fe\u63a5\uff0c\u8fd9\u662f\u6781\u5927\u7684\u5360\u670d\u52a1\u5668\u8d44\u6e90\u7684\u4e8b\u60c5\uff0c\u5c24\u5176\u662f\u5185\u5b58\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5982\u679c\u4f60\u628a\u4f60\u7684\u8868\u9501\u4e0a\u4e00\u6bb5\u65f6\u95f4\uff0c\u6bd4\u598230\u79d2\u949f\uff0c\u90a3\u4e48\u5bf9\u4e8e\u4e00\u4e2a\u6709\u5f88\u9ad8\u8bbf\u95ee\u91cf\u7684\u7ad9\u70b9\u6765\u8bf4\uff0c\u8fd930\u79d2\u6240\u79ef\u7d2f\u7684\u8bbf\u95ee\u8fdb\u7a0b\/\u7ebf\u7a0b\uff0c\u6570\u636e\u5e93\u94fe\u63a5\uff0c\u6253\u5f00\u7684\u6587\u4ef6\u6570\uff0c\u53ef\u80fd\u4e0d\u4ec5\u4ec5\u4f1a\u8ba9\u4f60\u6ccaWEB\u670d\u52a1Crash\uff0c\u8fd8\u53ef\u80fd\u4f1a\u8ba9\u4f60\u7684\u6574\u53f0\u670d\u52a1\u5668\u9a6c\u4e0a\u639b\u4e86\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u6240\u4ee5\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5927\u7684\u5904\u7406\uff0c\u4f60\u5b9a\u4f60\u4e00\u5b9a\u628a\u5176\u62c6\u5206\uff0c\u4f7f\u7528 LIMIT \u6761\u4ef6\u662f\u4e00\u4e2a\u597d\u7684\u65b9\u6cd5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre class=\"language-php\"><code>while (1) {\r\n    \/\/\u6bcf\u6b21\u53ea\u505a1000\u6761\r\n    mysql_query(\"DELETE FROM logs WHERE log_date &lt;= '2009-11-01' LIMIT 1000\");\r\n    if (mysql_affected_rows() == 0) {\r\n        \/\/ \u6ca1\u5f97\u53ef\u5220\u4e86\uff0c\u9000\u51fa\uff01\r\n        break;\r\n    }\r\n    \/\/ \u6bcf\u6b21\u90fd\u8981\u4f11\u606f\u4e00\u4f1a\u513f\r\n    usleep(50000);\r\n}<\/code><\/pre>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">18. \u8d8a\u5c0f\u7684\u5217\u4f1a\u8d8a\u5feb<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5bf9\u4e8e\u5927\u591a\u6570\u7684\u6570\u636e\u5e93\u5f15\u64ce\u6765\u8bf4\uff0c\u786c\u76d8\u64cd\u4f5c\u53ef\u80fd\u662f\u6700\u91cd\u5927\u7684\u74f6\u9888\u3002\u6240\u4ee5\uff0c\u628a\u4f60\u7684\u6570\u636e\u53d8\u5f97\u7d27\u51d1\u4f1a\u5bf9\u8fd9\u79cd\u60c5\u51b5\u975e\u5e38\u6709\u5e2e\u52a9\uff0c\u56e0\u4e3a\u8fd9\u51cf\u5c11\u4e86\u5bf9\u786c\u76d8\u7684\u8bbf\u95ee\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u53c2\u770b MySQL \u7684\u6587\u6863\u00a0<a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/storage-requirements.html\" target=\"_blank\" rel=\"noopener\">Storage Requirements<\/a>\u00a0\u67e5\u770b\u6240\u6709\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5982\u679c\u4e00\u4e2a\u8868\u53ea\u4f1a\u6709\u51e0\u5217\u7f62\u4e86\uff08\u6bd4\u5982\u8bf4\u5b57\u5178\u8868\uff0c\u914d\u7f6e\u8868\uff09\uff0c\u90a3\u4e48\uff0c\u6211\u4eec\u5c31\u6ca1\u6709\u7406\u7531\u4f7f\u7528 INT \u6765\u505a\u4e3b\u952e\uff0c\u4f7f\u7528 MEDIUMINT, SMALLINT \u6216\u662f\u66f4\u5c0f\u7684 TINYINT \u4f1a\u66f4\u7ecf\u6d4e\u4e00\u4e9b\u3002\u5982\u679c\u4f60\u4e0d\u9700\u8981\u8bb0\u5f55\u65f6\u95f4\uff0c\u4f7f\u7528 DATE \u8981\u6bd4 DATETIME \u597d\u5f97\u591a\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5f53\u7136\uff0c\u4f60\u4e5f\u9700\u8981\u7559\u591f\u8db3\u591f\u7684\u6269\u5c55\u7a7a\u95f4\uff0c\u4e0d\u7136\uff0c\u4f60\u65e5\u540e\u6765\u5e72\u8fd9\u4e2a\u4e8b\uff0c\u4f60\u4f1a\u6b7b\u7684\u5f88\u96be\u770b\uff0c\u53c2\u770b<a style=\"color: #78afd3;\" href=\"http:\/\/news.slashdot.org\/article.pl?sid=06\/11\/09\/1534204\" target=\"_blank\" rel=\"noopener\">Slashdot\u7684\u4f8b\u5b50<\/a>\uff082009\u5e7411\u670806\u65e5\uff09\uff0c\u4e00\u4e2a\u7b80\u5355\u7684ALTER TABLE\u8bed\u53e5\u82b1\u4e863\u4e2a\u591a\u5c0f\u65f6\uff0c\u56e0\u4e3a\u91cc\u9762\u6709\u4e00\u5343\u516d\u767e\u4e07\u6761\u6570\u636e\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">19. \u9009\u62e9\u6b63\u786e\u7684\u5b58\u50a8\u5f15\u64ce<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5728 MySQL \u4e2d\u6709\u4e24\u4e2a\u5b58\u50a8\u5f15\u64ce MyISAM \u548c InnoDB\uff0c\u6bcf\u4e2a\u5f15\u64ce\u90fd\u6709\u5229\u6709\u5f0a\u3002\u9177\u58f3\u4ee5\u524d\u6587\u7ae0\u300a<a style=\"color: #78afd3;\" href=\"https:\/\/coolshell.cn\/articles\/652.html\" target=\"_blank\" rel=\"noopener\">MySQL: InnoDB \u8fd8\u662f MyISAM?<\/a>\u300b\u8ba8\u8bba\u548c\u8fd9\u4e2a\u4e8b\u60c5\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">MyISAM \u9002\u5408\u4e8e\u4e00\u4e9b\u9700\u8981\u5927\u91cf\u67e5\u8be2\u7684\u5e94\u7528\uff0c\u4f46\u5176\u5bf9\u4e8e\u6709\u5927\u91cf\u5199\u64cd\u4f5c\u5e76\u4e0d\u662f\u5f88\u597d\u3002\u751a\u81f3\u4f60\u53ea\u662f\u9700\u8981update\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6574\u4e2a\u8868\u90fd\u4f1a\u88ab\u9501\u8d77\u6765\uff0c\u800c\u522b\u7684\u8fdb\u7a0b\uff0c\u5c31\u7b97\u662f\u8bfb\u8fdb\u7a0b\u90fd\u65e0\u6cd5\u64cd\u4f5c\u76f4\u5230\u8bfb\u64cd\u4f5c\u5b8c\u6210\u3002\u53e6\u5916\uff0cMyISAM \u5bf9\u4e8e SELECT COUNT(*) \u8fd9\u7c7b\u7684\u8ba1\u7b97\u662f\u8d85\u5feb\u65e0\u6bd4\u7684\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">InnoDB \u7684\u8d8b\u52bf\u4f1a\u662f\u4e00\u4e2a\u975e\u5e38\u590d\u6742\u7684\u5b58\u50a8\u5f15\u64ce\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u5c0f\u7684\u5e94\u7528\uff0c\u5b83\u4f1a\u6bd4 MyISAM \u8fd8\u6162\u3002\u4ed6\u662f\u5b83\u652f\u6301\u201c\u884c\u9501\u201d \uff0c\u4e8e\u662f\u5728\u5199\u64cd\u4f5c\u6bd4\u8f83\u591a\u7684\u65f6\u5019\uff0c\u4f1a\u66f4\u4f18\u79c0\u3002\u5e76\u4e14\uff0c\u4ed6\u8fd8\u652f\u6301\u66f4\u591a\u7684\u9ad8\u7ea7\u5e94\u7528\uff0c\u6bd4\u5982\uff1a\u4e8b\u52a1\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4e0b\u9762\u662fMySQL\u7684\u624b\u518c<\/p>\n<ul style=\"list-style-type: circle; margin-left: 30px; padding-left: 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\n<li style=\"list-style-type: disc; margin-left: 10px;\"><a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/myisam-storage-engine.html\">target=\u201d_blank\u201dMyISAM Storage Engine<\/a><\/li>\n<li style=\"list-style-type: disc; margin-left: 10px;\"><a style=\"color: #78afd3;\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/innodb.html\" target=\"_blank\" rel=\"noopener\">InnoDB Storage Engine<\/a><\/li>\n<\/ul>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">20. \u4f7f\u7528\u4e00\u4e2a\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\u5668\uff08Object Relational Mapper\uff09<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u4f7f\u7528 ORM (Object Relational Mapper)\uff0c\u4f60\u80fd\u591f\u83b7\u5f97\u53ef\u9760\u7684\u6027\u80fd\u589e\u6da8\u3002\u4e00\u4e2aORM\u53ef\u4ee5\u505a\u7684\u6240\u6709\u4e8b\u60c5\uff0c\u4e5f\u80fd\u88ab\u624b\u52a8\u7684\u7f16\u5199\u51fa\u6765\u3002\u4f46\u662f\uff0c\u8fd9\u9700\u8981\u4e00\u4e2a\u9ad8\u7ea7\u4e13\u5bb6\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">ORM \u7684\u6700\u91cd\u8981\u7684\u662f\u201cLazy Loading\u201d\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u53ea\u6709\u5728\u9700\u8981\u7684\u53bb\u53d6\u503c\u7684\u65f6\u5019\u624d\u4f1a\u53bb\u771f\u6b63\u7684\u53bb\u505a\u3002\u4f46\u4f60\u4e5f\u9700\u8981\u5c0f\u5fc3\u8fd9\u79cd\u673a\u5236\u7684\u526f\u4f5c\u7528\uff0c\u56e0\u4e3a\u8fd9\u5f88\u6709\u53ef\u80fd\u4f1a\u56e0\u4e3a\u8981\u53bb\u521b\u5efa\u5f88\u591a\u5f88\u591a\u5c0f\u7684\u67e5\u8be2\u53cd\u800c\u4f1a\u964d\u4f4e\u6027\u80fd\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">ORM \u8fd8\u53ef\u4ee5\u628a\u4f60\u7684SQL\u8bed\u53e5\u6253\u5305\u6210\u4e00\u4e2a\u4e8b\u52a1\uff0c\u8fd9\u4f1a\u6bd4\u5355\u72ec\u6267\u884c\u4ed6\u4eec\u5feb\u5f97\u591a\u5f97\u591a\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u76ee\u524d\uff0c\u4e2a\u4eba\u6700\u559c\u6b22\u7684PHP\u7684ORM\u662f\uff1a<a style=\"color: #78afd3;\" href=\"http:\/\/www.doctrine-project.org\/\" target=\"_blank\" rel=\"noopener\">Doctrine<\/a>\u3002<\/p>\n<h4 style=\"font-size: 14px; margin: 10px 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #ffffff;\">21. \u5c0f\u5fc3\u201c\u6c38\u4e45\u94fe\u63a5\u201d<\/h4>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u201c\u6c38\u4e45\u94fe\u63a5\u201d\u7684\u76ee\u7684\u662f\u7528\u6765\u51cf\u5c11\u91cd\u65b0\u521b\u5efaMySQL\u94fe\u63a5\u7684\u6b21\u6570\u3002\u5f53\u4e00\u4e2a\u94fe\u63a5\u88ab\u521b\u5efa\u4e86\uff0c\u5b83\u4f1a\u6c38\u8fdc\u5904\u5728\u8fde\u63a5\u7684\u72b6\u6001\uff0c\u5c31\u7b97\u662f\u6570\u636e\u5e93\u64cd\u4f5c\u5df2\u7ecf\u7ed3\u675f\u4e86\u3002\u800c\u4e14\uff0c\u81ea\u4ece\u6211\u4eec\u7684Apache\u5f00\u59cb\u91cd\u7528\u5b83\u7684\u5b50\u8fdb\u7a0b\u540e\u2014\u2014\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0b\u4e00\u6b21\u7684HTTP\u8bf7\u6c42\u4f1a\u91cd\u7528Apache\u7684\u5b50\u8fdb\u7a0b\uff0c\u5e76\u91cd\u7528\u76f8\u540c\u7684 MySQL \u94fe\u63a5\u3002<\/p>\n<ul style=\"list-style-type: circle; margin-left: 30px; padding-left: 0px; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\n<li style=\"list-style-type: disc; margin-left: 10px;\"><a style=\"color: #78afd3;\" href=\"http:\/\/php.net\/manual\/en\/function.mysql-pconnect.php\" target=\"_blank\" rel=\"noopener\">PHP\u624b\u518c\uff1amysql_pconnect()<\/a><\/li>\n<\/ul>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u5728\u7406\u8bba\u4e0a\u6765\u8bf4\uff0c\u8fd9\u542c\u8d77\u6765\u975e\u5e38\u7684\u4e0d\u9519\u3002\u4f46\u662f\u4ece\u4e2a\u4eba\u7ecf\u9a8c\uff08\u4e5f\u662f\u5927\u591a\u6570\u4eba\u7684\uff09\u4e0a\u6765\u8bf4\uff0c\u8fd9\u4e2a\u529f\u80fd\u5236\u9020\u51fa\u6765\u7684\u9ebb\u70e6\u4e8b\u66f4\u591a\u3002\u56e0\u4e3a\uff0c\u4f60\u53ea\u6709\u6709\u9650\u7684\u94fe\u63a5\u6570\uff0c\u5185\u5b58\u95ee\u9898\uff0c\u6587\u4ef6\u53e5\u67c4\u6570\uff0c\u7b49\u7b49\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u800c\u4e14\uff0cApache \u8fd0\u884c\u5728\u6781\u7aef\u5e76\u884c\u7684\u73af\u5883\u4e2d\uff0c\u4f1a\u521b\u5efa\u5f88\u591a\u5f88\u591a\u7684\u4e86\u8fdb\u7a0b\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u8fd9\u79cd\u201c\u6c38\u4e45\u94fe\u63a5\u201d\u7684\u673a\u5236\u5de5\u4f5c\u5730\u4e0d\u597d\u7684\u539f\u56e0\u3002\u5728\u4f60\u51b3\u5b9a\u8981\u4f7f\u7528\u201c\u6c38\u4e45\u94fe\u63a5\u201d\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u597d\u597d\u5730\u8003\u8651\u4e00\u4e0b\u4f60\u7684\u6574\u4e2a\u7cfb\u7edf\u7684\u67b6\u6784\u3002<\/p>\n<p style=\"margin: 10px auto; font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\">\u8f6c\u81ea\u00a0<a href=\"https:\/\/coolshell.cn\/articles\/1846.html\">https:\/\/coolshell.cn\/articles\/1846.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\uff0c\u6570\u636e\u5e93\u7684\u64cd\u4f5c\u8d8a\u6765\u8d8a\u6210\u4e3a\u6574\u4e2a\u5e94\u7528\u7684\u6027\u80fd\u74f6\u9888\u4e86\uff0c\u8fd9\u70b9\u5bf9\u4e8eWeb\u5e94\u7528\u5c24\u5176\u660e\u663e\u3002\u5173\u4e8e\u6570\u636e\u5e93\u7684\u6027\u80fd\uff0c\u8fd9\u5e76\u4e0d\u53ea\u662fDB [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[32],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-32"],"_links":{"self":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=170"}],"version-history":[{"count":0,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/170\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}