{"id":72,"date":"2016-09-28T05:32:40","date_gmt":"2016-09-27T20:32:40","guid":{"rendered":"http:\/\/okamurax.com\/?p=72"},"modified":"2020-05-05T01:20:15","modified_gmt":"2020-05-04T16:20:15","slug":"php-sqlite%e3%81%ab%e6%8e%a5%e7%b6%9a","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=72","title":{"rendered":"PHP SQLite\u306b\u63a5\u7d9a"},"content":{"rendered":"<pre class=\"lang:php decode:true \">&lt;?php\r\n\r\nClass User{\r\n\t\r\n    static public $salt = \"mwefCMEP28DjwdW3lwdS239vVS\";\r\n\t\r\n}\r\n\r\nclass Db{\r\n\r\n    public static $d;\r\n    static public function con(){\r\n        \r\n        $passwd = md5(\"1234\" . User::$salt);\r\n        \r\n        try{\r\n\t\t\t\r\n            self::$d = new PDO('sqlite::memory:',null,null);\r\n            self::$d-&gt;setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);\r\n            \r\n            self::$d-&gt;exec(\"create table if not exists tbl(id, user, password)\");\r\n            self::$d-&gt;exec(\"insert into tbl (id,user,password) values (1,'taro','$passwd')\");\r\n            \r\n        }catch(PDOException $e){\r\n\t\t\t\r\n            self::$d = null;\r\n            exit($e-&gt;getMessage());\r\n\t\t\t\r\n        }   \r\n    }\r\n}\r\n\r\nclass Main{\r\n\t\r\n    function __construct(){\r\n        \r\n        Db::con();\r\n        \r\n        if(isset($_POST[\"user\"]) &amp;&amp; isset($_POST[\"password\"])){\r\n\r\n            $passwd = md5($_POST[\"password\"] . User::$salt);\r\n            \r\n            $stmt = Db::$d-&gt;prepare(\"select * from tbl where password = ?\"); \/\/ \u3053\u3053\u3067 where password = '?'\u3000\u3068\u3057\u3066\u3044\u305f\u3089\u30a8\u30e9\u30fc\u3002\r\n            $stmt-&gt;execute(array($passwd));\r\n\t\t\t\r\n            $res = $stmt-&gt;fetchAll(PDO::FETCH_BOTH);\r\n            \r\n            if(isset($res[0][\"password\"])){\r\n                \r\n                echo \"\u30ed\u30b0\u30a4\u30f3\u4e2d\", $res[0][\"user\"], \"\u3055\u3093\";\r\n                \r\n            }else{\r\n                \r\n                sleep(2);\r\n                echo \"\u30ed\u30b0\u30a4\u30f3\u5931\u6557\";\r\n                echo '&lt;form method=\"POST\" action=\"\"&gt;';\r\n                echo '  &lt;input type=\"text\" name=\"user\"&gt;';\r\n                echo '  &lt;input type=\"password\" name=\"password\"&gt;';\r\n                echo '  &lt;input type=\"submit\"&gt;';\r\n                echo '&lt;\/form&gt;'; \r\n                \r\n            }\r\n            \r\n        } else {\r\n            \r\n            echo '&lt;form method=\"POST\" action=\"\"&gt;';\r\n            echo '  &lt;input type=\"text\" name=\"user\"&gt;';\r\n            echo '  &lt;input type=\"password\" name=\"password\"&gt;';\r\n            echo '  &lt;input type=\"submit\"&gt;';\r\n            echo '&lt;\/form&gt;';\r\n            \r\n        }\r\n    }\r\n}\r\n\r\nnew Main();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php Class User{ static public $salt = &#8220;mwefCMEP28DjwdW3lwdS239vVS&#8221;; } class Db{ public static $d; static  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=72\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;PHP SQLite\u306b\u63a5\u7d9a&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-1","tag-php"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=72"}],"version-history":[{"count":3,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":1859,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions\/1859"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}