{"id":189,"date":"2010-02-09T23:37:22","date_gmt":"2010-02-09T14:37:22","guid":{"rendered":"http:\/\/www.lancard.com\/blog\/?p=189"},"modified":"2025-03-12T11:31:55","modified_gmt":"2025-03-12T02:31:55","slug":"utf-8-cakephp-euc-jp-mysql4-0","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2010\/02\/09\/utf-8-cakephp-euc-jp-mysql4-0\/","title":{"rendered":"UTF-8\u306aCakePHP+EUC-JP\u306aMySQL4.0"},"content":{"rendered":"<p>CakePHP\u306f\u975e\u5e38\u306b\u826f\u304f\u3067\u304d\u305fPHP\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002<br \/>\nDB\u306e\u7a2e\u985e\u7b49\u3082\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u5c11\u3057\u66f8\u3044\u3066\u3084\u308b\u3060\u3051\u3067\u52d5\u3044\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>\u6587\u5b57\u30b3\u30fc\u30c9\u3082\u305d\u3046\u3067\u4e0b\u8a18\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304f\u3060\u3051\u3067\u3059\u3002<br \/>\nMySQL\u3067EUC-JP\u3092\u6271\u3046\u5834\u5408\u3082\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<pre lang=\"php\" line=\"1\">\n\/app\/config\/database.php\n<?php\nclass DATABASE_CONFIG {\n\n    var $default = array(\n        &#039;driver&#039; => &#039;mysql&#039;,\n        &#039;persistent&#039; => false,\n        &#039;host&#039; => &#039;localhost&#039;,\n        &#039;port&#039;=>3306,\n        &#039;database&#039; => &#039;dbname&#039;,\n        &#039;login&#039; => &#039;dbuser&#039;,\n        &#039;password&#039; => &#039;dbpassword&#039;,\n        &#039;prefix&#039; => &#039;&#039;,\n        &#039;encoding&#039; => &#039;ujis&#039;,\n    );\n\n}\n?>\n<\/pre>\n<p>MySQL\u306e\u5834\u5408\u306f\u3053\u3053\u3067\u8a2d\u5b9a\u3057\u305fencoding\u3092\u4f7f\u3063\u3066\u3001\u300cSET NAMES ujis;\u300d\u3092\u81ea\u52d5\u7684\u306b\u767a\u884c\u3057\u3066\u304f\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u3053\u3067\u554f\u984c\u304c\u767a\u751f\u3057\u305f\u306e\u3067\u3059\u304c\u3001MySQL4.0\u7cfb\u306b\u306fSET NAMES\u69cb\u6587\u304c\u306a\u3044\u306e\u3067\u6587\u5b57\u5316\u3051\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002CakePHP\u5074\u3082EUC-JP\u306b\u3057\u3066\u3057\u307e\u3048\u3070\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306fUTF-8\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001DB\u3068\u306e\u5165\u51fa\u529b\u306e\u969b\u306b\u3001UTF-8\u21d4EUC-JP\u3068\u5909\u63db\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002CakePHP\u306f\u30c7\u30fc\u30bf\u64cd\u4f5c\u306e\u969b\u306b\u547c\u3070\u308c\u308b\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u305d\u3053\u3067\u5909\u63db\u3057\u3066\u3084\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<p>\u57fa\u672c\u7684\u306b\u5168\u3066\u306e\u751f\u6210\u3055\u308c\u305fModel\u306fAppModel\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u306e\u30af\u30e9\u30b9\u3067\u5909\u63db\u3057\u3066\u3084\u308a\u307e\u3059\u3002<\/p>\n<pre lang=\"php\" line=\"1\">\n\/app\/config\/app_model.php\n<?php\nclass AppModel extends Model {\n\n    \/\/\u30c7\u30fc\u30bf\u53d6\u5f97\u5f8c\u306b\u547c\u3070\u308c\u308b\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\n    function afterFind($results) {\n        \/\/$results\u914d\u5217\u3092UTF-8\u306b\u5909\u63db\u3059\u308b\u51e6\u7406\n        \n        return $results;\n    }\n\n    \/\/\u30c7\u30fc\u30bf\u4fdd\u5b58\u524d\u306b\u547c\u3070\u308c\u308b\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570    \n    function beforeSave() {\n        \/\/$this->data\u914d\u5217\u3092EUC-JP\u306b\u5909\u63db\u3059\u308b\u51e6\u7406\n\n        return true;\n    }\n}\n?>\n<\/pre>\n<p>\u3082\u3063\u3068\u6839\u3063\u3053\u306e\u3068\u3053\u308d\u3067\u5909\u63db\u304b\u3051\u3066\u3082\u826f\u3044\u306e\u3067\u3057\u3087\u3046\u304c\u3001\u4eca\u56de\u306fCakePHP\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u306f\u624b\u3092\u52a0\u3048\u305f\u304f\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u3053\u3046\u3057\u307e\u3057\u305f\u3002\u5b50\u30af\u30e9\u30b9\u3067\u4e0a\u8a18\u95a2\u6570\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u89aa\u306e\u95a2\u6570\u3092\u547c\u3076\u306e\u3092\u304a\u5fd8\u308c\u306a\u304f\u3002\u3053\u3046\u3057\u305f\u307b\u3046\u304c\u826f\u3044\u3068\u3044\u3046\u306e\u304c\u3042\u308c\u3070\u30c4\u30c3\u30b3\u30df\u304a\u5f85\u3061\u3057\u3066\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%2F189&amp;t=UTF-8%E3%81%AACakePHP%2BEUC-JP%E3%81%AAMySQL4.0&amp;s=100&amp;p[url]=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F189&amp;p[images][0]=&amp;p[title]=UTF-8%E3%81%AACakePHP%2BEUC-JP%E3%81%AAMySQL4.0\" 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%2F189&amp;text=UTF-8%E3%81%AACakePHP%2BEUC-JP%E3%81%AAMySQL4.0\" 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&amp;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F189&amp;title=UTF-8%E3%81%AACakePHP%2BEUC-JP%E3%81%AAMySQL4.0\" 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=&amp;v=3&amp;t=UTF-8%E3%81%AACakePHP%2BEUC-JP%E3%81%AAMySQL4.0&amp;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F189\" 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=UTF-8%E3%81%AACakePHP%2BEUC-JP%E3%81%AAMySQL4.0&amp;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%2F189\" 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\u306f\u975e\u5e38\u306b\u826f\u304f\u3067\u304d\u305fPHP\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002 DB\u306e\u7a2e\u985e\u7b49\u3082\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u5c11\u3057\u66f8\u3044\u3066\u3084\u308b\u3060\u3051\u3067\u52d5\u3044\u3066\u304f\u308c\u307e\u3059\u3002 \u6587\u5b57\u30b3\u30fc\u30c9\u3082\u305d\u3046\u3067\u4e0b\u8a18\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304f\u3060\u3051\u3067\u3059\u3002 MySQL\u3067EUC-JP\u3092\u6271\u3046\u5834\u5408\u3082\u4e0b\u8a18\u306e [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[24],"class_list":["post-189","post","type-post","status-publish","format-standard","hentry","category-1","tag-cakephp"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/189","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\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=189"}],"version-history":[{"count":19,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":4729,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/189\/revisions\/4729"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}