{"id":396,"date":"2017-02-05T20:37:07","date_gmt":"2017-02-05T12:37:07","guid":{"rendered":"http:\/\/www.rainweb.site\/?p=396"},"modified":"2023-08-07T20:57:30","modified_gmt":"2023-08-07T12:57:30","slug":"php-article26","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2017\/02\/05\/php-article26\/","title":{"rendered":"PHP\u5bf9mysql\u6570\u636e\u6d41\u8fdb\u884c\u589e\u5220\u6539\u67e5"},"content":{"rendered":"<h3>\u8fd9\u7bc7\u535a\u6587\u4e3b\u8981\u8bb2\u89e3\u6211\u5728\u4f7f\u7528PHP\u8fc7\u7a0b\u4e2d\u5e38\u7528\u7684mysql\u8bed\u53e5\u64cd\u4f5c\uff0c\u8fd9\u7bc7\u535a\u6587\u4e3b\u8981\u8bb2\u89e3\u6211\u5728\u4f7f\u7528PHP\u8fc7\u7a0b\u4e2d\u5e38\u7528\u7684mysql\u8bed\u53e5\u64cd\u4f5c\uff1b\u8fd9\u7bc7\u535a\u6587\u4e3b\u8981\u8bb2\u89e3\u6211\u5728\u4f7f\u7528PHP\u8fc7\u7a0b\u4e2d\u5e38\u7528\u7684mysql\u8bed\u53e5\u64cd\u4f5c<\/h3>\n<h3>\u4e00.\u67e5\u8be2\u6570\u636e\u5e93<\/h3>\n<pre><code>\/\/\u67e5\u8be2\u6570\u636e\u8868\u4e2d\u7684\u6240\u6709\u6570\u636e\n$result = mysql_query(\"SELECT * FROM tablename\");\n\/\/\u67e5\u8be2\u67d0\u4e2aid\u6240\u5bf9\u5e94\u7684\u6570\u636e\n$id = 1;\n$result = mysql_query(\"SELECT * FROM article where id=\".$id);\n\/\/\u67e5\u8be2\u6309\u7167id\u6392\u5e8f\u7684\u6240\u6709\u6570\u636e\n$result = mysql_query(\"SELECT * FROM users ORDER BY id DESC\");\n\/\/\u83b7\u53d6\u6570\u636e\u8868\u7684\u6570\u636e\u6761\u6570\n$dataCount = mysql_num_rows($result);\n#\u6253\u5370\u8f93\u51fa\u67e5\u8be2\u5230\u7684\u4e00\u6761\u5185\u5bb9\n$row = mysql_fetch_array($result);\necho $row['id']'\n#\u6253\u5370\u8f93\u51fa\u67e5\u8be2\u5230\u7684\u6240\u6709\u5185\u5bb9\uff0c\u56e0\u4e3a\u662f\u591a\u7ef4\u6570\u7ec4\uff0c\u4f7f\u7528while\u5faa\u73af\nwhile($row = mysql_fetch_array($result)){\necho $row['id']'\n}\n<\/code><\/pre>\n<h3>\u4e8c.\u6dfb\u52a0\u6570\u636e<\/h3>\n<pre><code>\/\/\u9996\u5148\u8fdb\u884c\u975e\u7a7a\u6392\u9519\nif(!isset($_POST['username'])){\ndie('username is not define');\n}\nif(empty($username)){\ndie('username is empty');\n}\n\/\/\u6267\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u9632\u6b62SQL\u6ce8\u5165\n$age=intval($age);\n\/\/\u63d2\u5165\u6570\u636e\nmysql_query(\"INSERT INTO tablename(username,password) VALUES ('$username',$password)\");\n\/\/\u5224\u65ad\u662f\u5426\u6210\u529f\u8fd4\u56de\u9875\u9762\nif(mysql_error()){\necho mysql_error();\n}else{\nheader(\"Location:index.php\");\n}\n<\/code><\/pre>\n<h5>\u7279\u522b\u63d0\u9192\u7684\u662f\uff1a\u5b57\u7b26\u4e32\u6570\u636e\u4e00\u5b9a\u8981\u52a0\u5f15\u53f7\uff0c\u975e\u5b57\u7b26\u4e32\u4e00\u5b9a\u8981\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u9632\u6b62SQL\u6ce8\u5165\uff0c\u4ee5\u4fdd\u8bc1\u6570\u636e\u5e93\u5b89\u5168\u3002<\/h5>\n<h3>\u4e09.\u4fee\u6539\u6570\u636e<\/h3>\n<pre><code>if(empty($_POST['id'])){\ndie('id is empty');\n}\nif(empty($_POST['username'])){\ndie('usernname is empty');\n}\n$id=intval($_POST['id']);\n$username=$_POST['username'];\nmysql_query(\"UPDATE users SET username='$username',password=$password WHERE id=$id\");\n\/\/\u6392\u9519\u5e76\u8fd4\u56de\nif(mysql_error()){\necho mysql_error();\n}else{\nheader(\"Location:index.php\");\n}\n<\/code><\/pre>\n<h3>\u56db.\u5220\u9664\u6570\u636e<\/h3>\n<pre><code>\/\/\u6392\u7a7a\u9519\u8bef\nif(empty($_GET['id'])){\ndie('id is empty');\n}\n$id=intval($_GET['id']);\nmysql_query(\"DELETE FROM users WHERE id=$id\");\n\/\/\u6392\u9519\u5e76\u8fd4\u56de\u9875\u9762\nif(mysql_error()){\necho mysql_error();\n}else{\nheader(\"Location:index.php\");\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u535a\u6587\u4e3b\u8981\u8bb2\u89e3\u6211\u5728\u4f7f\u7528PHP\u8fc7\u7a0b\u4e2d\u5e38\u7528\u7684mysql\u8bed\u53e5\u64cd\u4f5c\uff0c\u8fd9\u7bc7\u535a\u6587\u4e3b\u8981\u8bb2\u89e3\u6211\u5728\u4f7f\u7528PHP\u8fc7\u7a0b\u4e2d\u5e38\u7528\u7684mys\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2017\/02\/05\/php-article26\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":397,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[34],"tags":[56,57],"class_list":["post-396","post","type-post","status-publish","format-aside","has-post-thumbnail","hentry","category-php","tag-mysql","tag-php","post_format-post-format-aside"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=396"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/396\/revisions"}],"predecessor-version":[{"id":1514,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/396\/revisions\/1514"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media\/397"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=396"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}