{"id":1013,"date":"2011-06-21T12:08:56","date_gmt":"2011-06-21T03:08:56","guid":{"rendered":"http:\/\/www.lancard.com\/blog\/?p=1013"},"modified":"2025-03-12T11:31:17","modified_gmt":"2025-03-12T02:31:17","slug":"php-sqlite-%e3%81%a7%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%8f%be%ef%bc%88pdo_sqlite%e7%b7%a8%ef%bc%89-in-cakephp","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2011\/06\/21\/php-sqlite-%e3%81%a7%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%8f%be%ef%bc%88pdo_sqlite%e7%b7%a8%ef%bc%89-in-cakephp\/","title":{"rendered":"PHP + SQLite \u3067\u6b63\u898f\u8868\u73fe\uff08PDO_SQLITE\u7de8\uff09 in CakePHP"},"content":{"rendered":"<p>CakePHP 1.3.6 \u3067\u306e\u8a71\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3001\u3084\u3063\u305f\u306e\u306f\u305a\u3044\u3076\u3093\u3068\u524d\u306a\u3093\u3067\u3059\u304c\u66f8\u3044\u3066\u306a\u304b\u3063\u305f\u3067\u3059\u306d\u3002<br \/>\n\u79c1\u306f\u3059\u3054\u304f\u3046\u308c\u3057\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u5468\u308a\u306e\u53cd\u5fdc\u306f\u8584\u304b\u3063\u305f\u899a\u3048\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>CakePHP 1.3 \u3067SQLite3\u3063\u3066\u306e\u306f\u304b\u306a\u308a\u30a4\u30ec\u30ae\u30e5\u30e9\u30fc\u3067\u3001\u78ba\u304b\u3001CakePHP\u306eTrac\u304b\u3089\u63a2\u3057\u3066\u304d\u305f\u30c9\u30e9\u30a4\u30d0\uff08dbo_sqlite3.php\uff09\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u78ba\u8a8d\u3057\u3088\u3046\u3068\u601d\u3063\u305f\u306e\u3067\u3059\u304cTrac\u306b\u7e4b\u304c\u3089\u306a\u3044\u305e\uff1f\u3063\u3066\u306a\u72b6\u6cc1\u3002<\/p>\n<p>\u305d\u3093\u306a\u3053\u3093\u306a\u3067\u3068\u3066\u3082\u30de\u30a4\u30ca\u30fc\u306a\u8a71\u306a\u3093\u3067\u3059\u3088\u306d\u3002\u3000\u53cd\u5fdc\u304c\u8584\u3044\u306e\u3082\u3080\u3079\u306a\u308b\u304b\u306a\u3002<\/p>\n<p>\u3067\u3059\u304c\u3001PDO\u3067SQLite\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3044\u308b\u5834\u5408\u306a\u3089\u5fdc\u7528\u304c\u52b9\u304f\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\ndbo_sqlite3.php \u5185\u90e8\u3067PDO\u304c\u4f7f\u7528\u3055\u308c\u3066\u304a\u308a\u307e\u3059\u306e\u3067\u3002<\/p>\n<p>app_model.php \u3067\u3084\u3063\u3066\u3044\u308b\u306e\u3067\u95a2\u4fc2\u3059\u308b\u3068\u3053\u308d\u3092\u307e\u3068\u3081\u3066\u5f15\u7528\u3002<\/p>\n<pre lang=\"Php\" line=\"1\">\r\nclass AppModel extends Model {\r\n    function beforeFind($queryData) {\r\n        parent::beforeFind($queryData);\r\n        \/\/\u6b63\u898f\u8868\u73fe\u95a2\u6570\u6709\u52b9\u5316\r\n        $this->regxEnable();\r\n    }\r\n\r\n    \/**\r\n     * \u6b63\u898f\u8868\u73fe\u95a2\u6570\u6709\u52b9\u5316\r\n     *\/\r\n    public function regxEnable(){\r\n        $db =& $this->getDataSource();\r\n        $db->connection->sqliteCreateFunction('RGX', array('AppModel', 'sqliteRegexMatch'), 2);\r\n    }\r\n\r\n    \/**\r\n     * \u6b63\u898f\u8868\u73fe\u95a2\u6570\r\n     *\/\r\n    public function sqliteRegexMatch($regex, $str) {\r\n        if(empty($regex)){\r\n            return true;\r\n        }else{\r\n            return preg_match($regex, $str);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>$db->connection \u304cPDO\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3067\u3059\u3002<br \/>\nsqliteRegexMatch \u3067 $regex \u304c empty \u306e\u5834\u5408\u306b true \u3092\u8fd4\u3057\u3066\u3044\u308b\u306e\u306f\u5b9f\u88c5\u3057\u3066\u3044\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u90fd\u5408\u3067\u3059\u306e\u3067\u3054\u6ce8\u610f\u3092\u3002<\/p>\n<p>\u5b9f\u88c5\u306e\u969b\u3001\u4e0b\u8a18\u30b5\u30a4\u30c8\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/www.karak.jp\/blog\/sqlite-regexp.html\">SQLite\u3067\u6b63\u898f\u8868\u73fe \u00ab karak<\/a><\/p>\n<p>\u9055\u3044\u306fPDO\u3067\u3042\u308b\u3053\u3068\u3001preg_match\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u3053\u3068\u3001SQL\u95a2\u6570\u3092\u51e6\u7406\u3059\u308b\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3068\u3057\u3066\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u3044\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\n<strong>CakePHP\u7684\u30dd\u30a4\u30f3\u30c8<\/strong><\/p>\n<ul>\n<li>DBO\u304b\u3089PDO\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u53d6\u5f97<\/li>\n<li>beforeFind\u3067\u691c\u7d22\u6642\u306b\u6b63\u898f\u8868\u73fe\u95a2\u6570\u3092\u6709\u52b9\u5316<\/li>\n<\/ul>\n<p><p>\n<strong>PDO_SQLITE\u7684\u30dd\u30a4\u30f3\u30c8<\/strong><\/p>\n<ul>\n<li>sqliteCreateFunction\u3067SQL\u95a2\u6570\u767b\u9332<\/li>\n<li>sqliteCreateFunction\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u767b\u9332\u3059\u308b\u969b\u306e\u66f8\u5f0f<\/li>\n<\/ul>\n<p>\n<p>\u4f7f\u3044\u65b9\u3067\u3059\u304c\u3001\u53c2\u8003\u30b5\u30a4\u30c8\u3068\u9055\u3063\u3066preg_match\u3067\u306e\u6b63\u898f\u8868\u73fe\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u79c1\u306e\u5834\u5408\u3001CakePHP\u3067\u306e\u4f7f\u7528\u3067\u3059\u306e\u3067<\/p>\n<pre lang=\"Php\" line=\"1\">\r\n    \/**\r\n     * \u30e2\u30c7\u30eb\u306econditons\u306b\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u3046\u5834\u5408\u306e\u914d\u5217\u3092\u8fd4\u3059\u3002\r\n     *\r\n     * @param <type> $pattern \u6b63\u898f\u8868\u73fe\r\n     * @param <type> $cols \u5224\u5b9a\u5bfe\u8c61\u306e\u30ab\u30e9\u30e0\u306e\u914d\u5217\r\n     * @return <bool>\r\n     *\/\r\n    function whereByRgx($pattern, $cols) {\r\n        $conditons = array();\r\n        if(!empty($pattern)){\r\n            foreach ($cols as $colname) {\r\n                $conditons[] = \"RGX('\" . $pattern . \"', \" . $colname . \")\";\r\n            }\r\n        }\r\n        return $conditons;\r\n    }\r\n<\/pre>\n<p>\u3066\u306a\u30e2\u30c7\u30eb\u3067\u306efind\u306a\u3069\u3067\u4f7f\u7528\u3059\u308bconditions\u7528\u306e\u914d\u5217\u3092\u8fd4\u3059\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u3063\u3066\u4f7f\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1013&#038;t=PHP%20%2B%20SQLite%20%E3%81%A7%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE%EF%BC%88PDO_SQLITE%E7%B7%A8%EF%BC%89%20in%20CakePHP&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1013&#038;p&#091;images&#093;&#091;0&#093;=&#038;p&#091;title&#093;=PHP%20%2B%20SQLite%20%E3%81%A7%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE%EF%BC%88PDO_SQLITE%E7%B7%A8%EF%BC%89%20in%20CakePHP\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"http:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1013&#038;text=PHP%20%2B%20SQLite%20%E3%81%A7%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE%EF%BC%88PDO_SQLITE%E7%B7%A8%EF%BC%89%20in%20CakePHP\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1013&#038;title=PHP%20%2B%20SQLite%20%E3%81%A7%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE%EF%BC%88PDO_SQLITE%E7%B7%A8%EF%BC%89%20in%20CakePHP\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-tumblr nolightbox\" data-provider=\"tumblr\" target=\"_blank\" rel=\"nofollow\" title=\"Share on tumblr\" href=\"https:\/\/tumblr.com\/share?s=&#038;v=3&#038;t=PHP%20%2B%20SQLite%20%E3%81%A7%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE%EF%BC%88PDO_SQLITE%E7%B7%A8%EF%BC%89%20in%20CakePHP&#038;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1013\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"tumblr\" title=\"Share on tumblr\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/tumblr.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=PHP%20%2B%20SQLite%20%E3%81%A7%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE%EF%BC%88PDO_SQLITE%E7%B7%A8%EF%BC%89%20in%20CakePHP&#038;body=%E3%82%B7%E3%82%A7%E3%82%A2%E3%81%99%E3%82%8B%EF%BC%9A:%20https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1013\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>CakePHP 1.3.6 \u3067\u306e\u8a71\u3067\u3059\u3002 \u3053\u308c\u3001\u3084\u3063\u305f\u306e\u306f\u305a\u3044\u3076\u3093\u3068\u524d\u306a\u3093\u3067\u3059\u304c\u66f8\u3044\u3066\u306a\u304b\u3063\u305f\u3067\u3059\u306d\u3002 \u79c1\u306f\u3059\u3054\u304f\u3046\u308c\u3057\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u5468\u308a\u306e\u53cd\u5fdc\u306f\u8584\u304b\u3063\u305f\u899a\u3048\u304c\u3042\u308a\u307e\u3059\u3002 CakePHP 1.3 \u3067SQLite3\u3063\u3066\u306e [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[24],"class_list":["post-1013","post","type-post","status-publish","format-standard","hentry","category-php","tag-cakephp"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=1013"}],"version-history":[{"count":34,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1049,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/1013\/revisions\/1049"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}