{"id":29,"date":"2016-10-22T14:48:57","date_gmt":"2016-10-22T05:48:57","guid":{"rendered":"http:\/\/www.dogrow.net\/php\/?p=29"},"modified":"2017-09-01T17:16:23","modified_gmt":"2017-09-01T08:16:23","slug":"blog4","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/php\/blog4\/","title":{"rendered":"(4) \u521d\u3081\u3066\u306eSQLite\uff08\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\uff09"},"content":{"rendered":"<h1 class=my_h>\u3084\u3063\u3066\u307f\u305f\u3044\u3053\u3068<\/h1>\n<p>\u7c21\u6613\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066SQLite\u306f\u3068\u3063\u3066\u3082\u4fbf\u5229\u3067\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306fPHP\u304b\u3089SQLite\u3092\u4f7f\u3063\u3066\u4ee5\u4e0b\u306e\u3053\u3068\u3092\u3084\u3063\u3066\u307f\u307e\u3059\u3002<br \/>\n(1) \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4f5c\u6210<br \/>\n(2) \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e0a\u306b\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210<br \/>\n(3) \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e0a\u306e\u30c6\u30fc\u30d6\u30eb\u3078\u306e\u30c7\u30fc\u30bf\u767b\u9332<br \/>\n(4) \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e0a\u306e\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u53c2\u7167<\/p>\n<h1 class=my_h>\u30d7\u30ed\u30b0\u30e9\u30e0\u4f5c\u6210<\/h1>\n<p>\u4eca\u56de\u4f5c\u6210\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4ed5\u69d8\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<br \/>\n\u30fbSQLite\u3067\u4f5c\u6210\u3057\u305f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9(\u4ee5\u4e0bDB)\u306b\u3001\u4eba\u540d\u3068\u767b\u9332\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u3002<br \/>\n\u30fb\u4eba\u540d\u306fWEB\u30d6\u30e9\u30a6\u30b6\u306e\u5f15\u6570 name \u3067\u6307\u5b9a\u3059\u308b\u3002<br \/>\n\u30fbSQLite\u306e DB\u30d5\u30a1\u30a4\u30eb\u540d\u306f mydb.db \u3068\u3059\u308b\u3002<br \/>\n\u30fb\u767b\u9332\u5b8c\u4e86\u5f8c\u3001\u65b0\u898f\u767b\u9332\u3057\u305f\u540d\u524d\u306b\u81ea\u52d5\u4ed8\u4e0e\u3055\u308c\u305fID\u3092\u8868\u793a\u3059\u308b\u3002<br \/>\n\u30fb\u767b\u9332\u5b8c\u4e86\u5f8c\u3001\u65e2\u5b58\u306e\u5168\u767b\u9332\u6e08\u307f\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;HTML&gt;\r\n&lt;HEAD&gt;\r\n&lt;META CHARSET=&quot;UTF-8&quot; \/&gt;\r\n&lt;TITLE&gt;SQLite\u30b5\u30f3\u30d7\u30eb&lt;\/TITLE&gt;\r\n&lt;\/HEAD&gt;\r\n&lt;\/BODY&gt;\r\n\r\n&lt;?php\r\n  $db_file_path = &quot;mydb.db&quot;;    \/\/ SQLite DB\u30d5\u30a1\u30a4\u30eb\u540d\r\n\r\n  \/\/ \u5f15\u6570\u304b\u3089\u65b0\u898f\u767b\u9332\u540d\u3092\u53d6\u5f97\r\n  $name = $_GET&#x5B;'name'];\r\n\r\n  \/\/ DB\u30d5\u30a1\u30a4\u30eb\u5b58\u5728\u78ba\u8a8d\r\n  $isDbExist = file_exists($db_file_path);\r\n\r\n  \/\/ DB\u30aa\u30fc\u30d7\u30f3\r\n  $db = new SQLite3($db_file_path);\r\n\r\n  \/\/ DB\u306f\u65b0\u898f\u4f5c\u6210\uff1f\r\n  if($isDbExist === FALSE){\r\n    \/\/ \u30c6\u30fc\u30d6\u30eb\u4f5c\u6210 (ID, \u540d\u524d, \u767b\u9332\u65e5\u6642)\r\n    $db-&gt;exec(&quot;CREATE TABLE mytbl (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, register DATETIME);&quot;);\r\n  }\r\n\r\n  \/\/ \u5f15\u6570\u3067\u6307\u5b9a\u3055\u308c\u305f\u540d\u524d\u3092\u65b0\u898f\u767b\u9332\r\n  $dateTime = strftime(time());\r\n  $db-&gt;exec(&quot;INSERT INTO `mytbl` (name,register) VALUES('$name', '$dateTime');&quot;);\r\n\r\n  \/\/ \u65b0\u898f\u767b\u9332\u3057\u305f\u540d\u524d\u306b\u81ea\u52d5\u4ed8\u4e0e\u3055\u308c\u305fID\u3092\u8868\u793a\r\n  echo &quot;New ID = &quot;.$db-&gt;lastInsertRowID().&quot;&lt;br \/&gt;&quot;;\r\n\r\n  \/\/ \u65e2\u5b58\u306e\u767b\u9332\u30c7\u30fc\u30bf\u3092\u4e00\u89a7\u8868\u793a\r\n  $result = $db-&gt;query(&quot;SELECT * FROM `mytbl`;&quot;);\r\n  while ($row = $result-&gt;fetchArray()) {\r\n      echo &quot;&lt;hr \/&gt;&quot;;\r\n      var_dump($row);\r\n  }\r\n  \/\/ DB\u30af\u30ed\u30fc\u30ba\r\n  $db-&gt;close();\r\n?&gt;\r\n\r\n&lt;\/BODY&gt;\r\n&lt;\/HTML&gt;\r\n<\/pre>\n<p>\u3000<br \/>\n\u5b9f\u884c\u30b5\u30f3\u30d7\u30eb\u306f\u3053\u3061\u3089\u3067\u3059\u3002<br \/>\n<a href=\"http:\/\/www.dogrow.net\/php\/sample\/00004\/?name=Jonny\" target=\"_blank\">http:\/\/www.dogrow.net\/php\/sample\/00004\/?name=Jonny<\/a><\/p>\n<h1 class=my_h>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u524a\u9664\u65b9\u6cd5\u306f\uff1f<\/h1>\n<p>SQLite\u3067\u306fDB\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308c\u3070OK\u3067\u3059\u3002<br \/>\n\u3059\u306a\u308f\u3061\u3001PHP\u30d7\u30ed\u30b0\u30e9\u30e0\u4e2d\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u3051\u3070\u3088\u3044\u3067\u3059\u3002<\/p>\n<pre class=my_pre>\r\n  unlink( \"\u30d5\u30a1\u30a4\u30eb\u540d\" );\r\n<\/pre>\n<hr class=my_hr_bottom>\n","protected":false},"excerpt":{"rendered":"<p>\u3084\u3063\u3066\u307f\u305f\u3044\u3053\u3068 \u7c21\u6613\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066SQLite\u306f\u3068\u3063\u3066\u3082\u4fbf\u5229\u3067\u3059\u3002 \u3053\u3053\u3067\u306fPHP\u304b\u3089SQLite\u3092\u4f7f\u3063\u3066\u4ee5\u4e0b\u306e\u3053\u3068\u3092\u3084\u3063\u3066\u307f\u307e\u3059\u3002 (1) \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4f5c\u6210 (2) \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e0a\u306b\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210 (3) \u30c7\u30fc\u30bf\u30d9\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/php\/blog4\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-2"],"views":2665,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":37,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":799,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/29\/revisions\/799"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}