{"id":96454,"date":"2024-10-20T09:35:17","date_gmt":"2024-10-20T01:35:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/96454\/"},"modified":"2024-10-20T09:35:17","modified_gmt":"2024-10-20T01:35:17","slug":"phpstudy%e6%95%99%e7%a8%8b%ef%bc%9a%e5%a6%82%e4%bd%95%e5%89%b5%e5%bb%ba%e5%92%8c%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e5%90%8d-phpstudy-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%90%8d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/96454\/","title":{"rendered":"PHPstudy\u6559\u7a0b\uff1a\u5982\u4f55\u5275\u5efa\u548c\u4f7f\u7528\u6578\u64da\u5eab\u540d (phpstudy \u6578\u64da\u5eab\u540d)"},"content":{"rendered":"<h1 id=\"phpstudy%e6%95%99%e7%a8%8b%ef%bc%9a%e5%a6%82%e4%bd%95%e5%89%b5%e5%bb%ba%e5%92%8c%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e5%90%8d-phpstudy-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%90%8d-rcWIBEhvOt\">PHPstudy\u6559\u7a0b\uff1a\u5982\u4f55\u5275\u5efa\u548c\u4f7f\u7528\u6578\u64da\u5eab\u540d (phpstudy \u6578\u64da\u5eab\u540d)<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u7db2\u7ad9\u9084\u662f\u5927\u578b\u61c9\u7528\u7a0b\u5e8f\uff0c\u6578\u64da\u5eab\u90fd\u80fd\u6709\u6548\u5730\u5b58\u5132\u548c\u7ba1\u7406\u6578\u64da\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 PHPstudy \u74b0\u5883\u4e2d\u5275\u5efa\u548c\u4f7f\u7528\u6578\u64da\u5eab\u540d\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u6578\u64da\u5eab\u7684\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-phpstudy%ef%bc%9f-rcWIBEhvOt\">\u4ec0\u9ebc\u662f PHPstudy\uff1f<\/h2>\n<p>PHPstudy \u662f\u4e00\u6b3e\u96c6\u6210\u4e86 PHP\u3001Apache\u3001MySQL \u548c\u5176\u4ed6\u958b\u767c\u5de5\u5177\u7684\u672c\u5730\u958b\u767c\u74b0\u5883\u3002\u5b83\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u5728\u672c\u5730\u5feb\u901f\u642d\u5efa\u7db2\u7ad9\uff0c\u9032\u884c\u6e2c\u8a66\u548c\u958b\u767c\u3002\u4f7f\u7528 PHPstudy\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5275\u5efa\u548c\u7ba1\u7406\u6578\u64da\u5eab\uff0c\u9019\u5c0d\u65bc\u5b78\u7fd2\u548c\u5be6\u8e10 PHP \u958b\u767c\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%ad%a5%e9%a9%9f-rcWIBEhvOt\">\u5275\u5efa\u6578\u64da\u5eab\u7684\u6b65\u9a5f<\/h2>\n<h3 id=\"1-%e5%95%9f%e5%8b%95-phpstudy-rcWIBEhvOt\">1. \u555f\u52d5 PHPstudy<\/h3>\n<p>\u9996\u5148\uff0c\u555f\u52d5 PHPstudy \u8edf\u4ef6\u3002\u7576\u4f60\u555f\u52d5\u5f8c\uff0c\u6703\u770b\u5230\u4e00\u500b\u63a7\u5236\u9762\u677f\uff0c\u9019\u88e1\u53ef\u4ee5\u555f\u52d5 Apache \u548c MySQL \u670d\u52d9\u3002\u78ba\u4fdd\u9019\u5169\u500b\u670d\u52d9\u90fd\u5df2\u7d93\u555f\u52d5\u3002<\/p>\n<h3 id=\"2-%e9%80%b2%e5%85%a5-phpmyadmin-rcWIBEhvOt\">2. \u9032\u5165 phpMyAdmin<\/h3>\n<p>\u5728 PHPstudy \u63a7\u5236\u9762\u677f\u4e2d\uff0c\u627e\u5230 phpMyAdmin \u7684\u9078\u9805\uff0c\u9ede\u64ca\u9032\u5165\u3002phpMyAdmin \u662f\u4e00\u500b\u7528\u65bc\u7ba1\u7406 MySQL \u6578\u64da\u5eab\u7684\u7db2\u9801\u61c9\u7528\u7a0b\u5e8f\uff0c\u63d0\u4f9b\u4e86\u53cb\u597d\u7684\u7528\u6236\u754c\u9762\u3002<\/p>\n<h3 id=\"3-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab-rcWIBEhvOt\">3. \u5275\u5efa\u6578\u64da\u5eab<\/h3>\n<p>\u5728 phpMyAdmin \u7684\u4e3b\u754c\u9762\u4e2d\uff0c\u4f60\u6703\u770b\u5230\u4e00\u500b\u300c\u6578\u64da\u5eab\u300d\u9078\u9805\u5361\u3002\u9ede\u64ca\u5b83\uff0c\u7136\u5f8c\u5728\u300c\u5275\u5efa\u6578\u64da\u5eab\u300d\u7684\u6587\u672c\u6846\u4e2d\u8f38\u5165\u4f60\u60f3\u8981\u7684\u6578\u64da\u5eab\u540d\u7a31\u3002\u9078\u64c7\u5b57\u7b26\u96c6\uff08\u901a\u5e38\u9078\u64c7 utf8mb4\uff09\uff0c\u7136\u5f8c\u9ede\u64ca\u300c\u5275\u5efa\u300d\u6309\u9215\u3002<\/p>\n<pre><code>CREATE DATABASE my_database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<h3 id=\"4-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e8%a1%a8-rcWIBEhvOt\">4. \u5275\u5efa\u6578\u64da\u8868<\/h3>\n<p>\u6578\u64da\u5eab\u5275\u5efa\u5b8c\u6210\u5f8c\uff0c\u9078\u64c7\u525b\u525b\u5275\u5efa\u7684\u6578\u64da\u5eab\uff0c\u7136\u5f8c\u9ede\u64ca\u300cSQL\u300d\u9078\u9805\u5361\u3002\u5728\u9019\u88e1\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 SQL \u8a9e\u53e5\u5275\u5efa\u6578\u64da\u8868\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    id INT(11) AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50) NOT NULL,\n    password VARCHAR(255) NOT NULL,\n    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab-rcWIBEhvOt\">\u4f7f\u7528\u6578\u64da\u5eab<\/h2>\n<h3 id=\"1-%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab-rcWIBEhvOt\">1. \u9023\u63a5\u6578\u64da\u5eab<\/h3>\n<p>\u5728 PHP \u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 PDO \u6216 MySQLi \u4f86\u9023\u63a5\u6578\u64da\u5eab\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 PDO \u9023\u63a5\u6578\u64da\u5eab\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n$dsn = 'mysql:host=localhost;dbname=my_database_name;charset=utf8mb4';\n$username = 'root';\n$password = '';\n\ntry {\n    $pdo = new PDO($dsn, $username, $password);\n    $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n    echo '\u6210\u529f\u9023\u63a5\u5230\u6578\u64da\u5eab';\n} catch (PDOException $e) {\n    echo '\u9023\u63a5\u5931\u6557: ' . $e-&gt;getMessage();\n}\n?&gt;<\/code><\/pre>\n<h3 id=\"2-%e5%9f%b7%e8%a1%8c%e6%9f%a5%e8%a9%a2-rcWIBEhvOt\">2. \u57f7\u884c\u67e5\u8a62<\/h3>\n<p>\u9023\u63a5\u6210\u529f\u5f8c\uff0c\u4f60\u53ef\u4ee5\u57f7\u884c SQL \u67e5\u8a62\u4f86\u64cd\u4f5c\u6578\u64da\u3002\u4f8b\u5982\uff0c\u63d2\u5165\u6578\u64da\uff1a<\/p>\n<pre><code>$stmt = $pdo-&gt;prepare(\"INSERT INTO users (username, password) VALUES (:username, :password)\");\n$stmt-&gt;execute(['username' =&gt; 'testuser', 'password' =&gt; 'testpass']);\n?&gt;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-rcWIBEhvOt\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 PHPstudy \u74b0\u5883\u4e2d\u5275\u5efa\u548c\u4f7f\u7528\u6578\u64da\u5eab\u540d\u3002\u901a\u904e\u7c21\u55ae\u7684\u6b65\u9a5f\uff0c\u4f60\u53ef\u4ee5\u8f15\u9b06\u5730\u8a2d\u7f6e\u6578\u64da\u5eab\u4e26\u9032\u884c\u64cd\u4f5c\u3002\u7121\u8ad6\u662f\u5b78\u7fd2\u9084\u662f\u5be6\u969b\u958b\u767c\uff0c\u638c\u63e1\u9019\u4e9b\u57fa\u672c\u6280\u80fd\u90fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5982\u679c\u4f60\u9700\u8981\u66f4\u9ad8\u6548\u7684\u958b\u767c\u74b0\u5883\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u9019\u5c07\u70ba\u4f60\u7684\u9805\u76ee\u63d0\u4f9b\u66f4\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728PHPStudy\u4e2d\u5275\u5efa\u548c\u4f7f\u7528\u6578\u64da\u5eab\u540d\uff0c\u638c\u63e1\u6578\u64da\u5eab\u7ba1\u7406\u7684\u57fa\u672c\u6280\u5de7\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\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-96454","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96454","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=96454"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96454\/revisions"}],"predecessor-version":[{"id":96455,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96454\/revisions\/96455"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=96454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=96454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=96454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}