{"id":532,"date":"2006-01-18T01:00:00","date_gmt":"2006-01-17T16:00:00","guid":{"rendered":"https:\/\/ecoop.net\/memo\/2006-01-18-1.html"},"modified":"2017-03-16T15:18:35","modified_gmt":"2017-03-16T06:18:35","slug":"2006-01-18-1","status":"publish","type":"post","link":"https:\/\/www.ecoop.net\/memo\/archives\/2006-01-18-1.html","title":{"rendered":"MySQL41 \u306e SJIS \u74b0\u5883\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u306e\u6587\u5b57\u5316\u3051\u3092\u9632\u3050"},"content":{"rendered":"<p>\nSJIS \u4ee5\u5916\u306f SET NAMES \u30af\u30a8\u30ea\u3067\u306e\u8a2d\u5b9a\u3067\u89e3\u6c7a\u3059\u308b\u304c\u3001SJIS \u3067\u306f\u30af\u30a8\u30ea\u3067\u306f\u89e3\u6c7a\u3067\u304d\u306a\u3044\u3002<br \/>\n&nbsp;<br \/>\n\u7d50\u8ad6\u304b\u3089\u3044\u3046\u3068\u3001<\/p>\n<blockquote><p>mysql &#8211;default-character-set=sjis [ -u username [ -p ]] [&#8230;]\n<\/p><\/blockquote>\n<p>\u306e\u3088\u3046\u306b\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3067\u306e\u63a5\u7d9a\u6642\u306b &#8211;default-character-set=sjis \u3068\u660e\u793a\u3057\u3066\u3084\u308b\u3060\u3051\u3067\u89e3\u6c7a\u3059\u308b(SET NAMES .. \u306f\u4e0d\u8981)\u3002my.cnf \u306e [mysql] \u306e\u9805\u76ee\u306b sjis \u3068\u8a2d\u5b9a\u3057\u3066\u3084\u3063\u3066\u3082\u3088\u3044\u3002<br \/>\n&nbsp;<br \/>\nPHP \u3067\u3082 my.cnf \u3092\u898b\u3066\u3044\u308b\u3089\u3057\u3044\u3002PHP \u3067\u306f\u3053\u308c\u4ee5\u5916\u306e\u59a5\u5f53\u306a\u8a2d\u5b9a\u306e\u624b\u6bb5\u304c\u306a\u3044\u3082\u3088\u3046\u3002<br \/>\n\u73fe\u5728\u306f\u3001\u4e00\u90e8\u306e\u30b3\u30fc\u30c9\u3067\u306e\u307f\u5bfe\u5fdc\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u81ea\u5206\u3067\u30e9\u30c3\u30d1\u95a2\u6570\u3092\u4f5c\u3063\u3066\u3084\u308b\u306e\u304c\u3088\u3055\u305d\u3046\u3002PEAR::DB \u306e prepared statement \u69cb\u6587\u3092\u4f7f\u3046\u5834\u5408\u306f  ujis (EUC_JP)\u3068\u3057\u3066\u901a\u4fe1\u3055\u305b\u3066\u3084\u3089\u306a\u3044\u3068\u3046\u307e\u304f\u3044\u304b\u306a\u304b\u3063\u305f\u3002<br \/>\n&nbsp;<br \/>\n\u8a73\u3057\u304f\u66f8\u304f\u3068\u3001DB_Common::prepare \u3067\u547c\u3073\u51fa\u3057\u3066\u3044\u308b\u5185\u90e8\u95a2\u6570\u3067\u975e UTF8 \u306e\u3064\u3082\u308a\u3067\u30a8\u30b9\u30b1\u30fc\u30d7\u51e6\u7406\u3092\u884c\u3046\u305f\u3081\u3001\u4e8b\u524d\u30a8\u30f3\u30b3\u30fc\u30c9\u3092\u3059\u308b\u3068\u6587\u5b57\u304c\u58ca\u308c\u3066\u3057\u307e\u3046\u306e\u304c\u539f\u56e0\u3002EUC-JP \u3060\u3068\u3001ASCII \u30b3\u30fc\u30c9\u306b\u4e92\u63db\u6027\u304c\u3042\u308b\u305f\u3081\u30a8\u30b9\u30b1\u30fc\u30d7\u51e6\u7406\u3067\u6587\u5b57\u304c\u58ca\u308c\u306a\u3044\u306e\u3067\u30a8\u30f3\u30b3\u30fc\u30c9\u5f8c\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u3067\u3082\u554f\u984c\u306a\u3044\u3002<br \/>\n&nbsp;\n<\/p>\n<blockquote><p>\/\/ <br \/>\n\/\/ \u5358\u7d14\u306a\u30b5\u30f3\u30d7\u30eb\u3002\u5b9f\u7528\u30b3\u30fc\u30c9\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3088\u3002<br \/>\n\/\/ <br \/>\n$con->query(&#8216;SET NAMES ujis&#8217;);<br \/>\necho dec( $con->getOne(enc(&#8216;SELECT description FROM product WHERE name = ?&#8217;), enc(array(&#8216;\u82db\u6027\u30bd\u30fc\u30c0&#8217;))) ) ;<\/p>\n<p>\/**<br \/>\n&nbsp;* <br \/>\n&nbsp;*\/<br \/>\nfunction dec($val){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return mb_convert_encoding($val, mb_internal_encoding(), &#8216;EUC-JP&#8217;);<br \/>\n}<br \/>\n\/** <br \/>\n&nbsp;* \u30a8\u30f3\u30b3\u30fc\u30c9\u3002\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3059\u308b\u524d\u306e\u524d\u51e6\u7406\u3002<br \/>\n&nbsp;* @param string  $val  \u5909\u63db\u5bfe\u8c61\u306e\u6587\u5b57\u5217<br \/>\n&nbsp;* @return string  DB \u30af\u30a8\u30ea\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u306b\u5909\u63db\u3057\u305f\u6587\u5b57\u5217<br \/>\n&nbsp;*\/<br \/>\nfunction enc($val){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return mb_convert_encoding($val, &#8216;EUC-JP&#8217;); <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ $val \u306f mb_internal_encoding() \u306e\u6587\u5b57\u30b3\u30fc\u30c9\u3002\u305d\u308c\u4ee5\u5916\u3082<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ \u53d7\u3051\u4ed8\u3051\u308b\u5834\u5408, \u7b2c\u4e09\u5f15\u6570\u3092 &#8216;auto,UTF-8&#8217; \u7b49\u306b\u3057\u3066\u304a\u304f\u3002<br \/>\n}\n<\/p><\/blockquote>\n<p>\u53c2\u8003:<br \/>\n&#8211; <a href=\"http:\/\/oss.timedia.co.jp\/index.fcgi\/kahua-web\/show\/MySQL%c6%fc%cb%dc%b8%ec%a4%ce%ce%b9\/%c0%dc%c2%b3%a5%ad%a5%e3%a5%e9%a5%af%a5%bf%a5%bb%a5%c3%a5%c8%a4%ce%ca%d1%b9%b9\">OSS Web &#8211; \u63a5\u7d9a\u30ad\u30e3\u30e9\u30af\u30bf\u30bb\u30c3\u30c8\u306e\u5909\u66f4<\/a><br \/>\n\u3053\u3053\u306b\u3042\u308b\u3068\u304a\u308a\u3001show variables like &#8216;character\\_set\\_%&#8217; \u3067\u306f\u540c\u3058\u306a\u306e\u306b\u3001\u5b9f\u969b\u306f\u5185\u90e8\u7684\u306b\u306f\u9055\u3046\u306e\u304c\u306a\u3093\u3068\u3082\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SJIS \u4ee5\u5916\u306f SET NAMES \u30af\u30a8\u30ea\u3067\u306e\u8a2d\u5b9a\u3067\u89e3\u6c7a\u3059\u308b\u304c\u3001SJIS \u3067\u306f\u30af\u30a8\u30ea\u3067\u306f\u89e3\u6c7a\u3067\u304d\u306a\u3044\u3002 &nbsp; \u7d50\u8ad6\u304b\u3089\u3044\u3046\u3068\u3001 mysql &#8211;default-character-set=sjis [ &hellip; <a href=\"https:\/\/www.ecoop.net\/memo\/archives\/2006-01-18-1.html\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">MySQL41 \u306e SJIS \u74b0\u5883\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u306e\u6587\u5b57\u5316\u3051\u3092\u9632\u3050<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[141],"tags":[26,32],"class_list":["post-532","post","type-post","status-publish","format-standard","hentry","category-lifehack","tag-mysql","tag-php"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/comments?post=532"}],"version-history":[{"count":0,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}