MySQL+PHP浜х敓涔辩爜鍘熷洜---杞浇
MySQL+PHP浜х敓涔辩爜鍘熷洜锛?
鈼?MySQL鏁版嵁搴撻粯璁ょ殑缂栫爜鏄痷tf8,濡傛灉杩欑缂栫爜涓庝綘鐨凱HP缃戦〉涓嶄竴鑷?鍙兘灏变細閫犳垚MySQL涔辩爜锛?
鈼?MySQL涓垱寤鸿〃鏃朵細璁╀綘閫夋嫨涓€绉嶇紪鐮?濡傛灉杩欑缂栫爜涓庝綘鐨勭綉椤电紪鐮佷笉涓€鑷?涔熷彲鑳介€犳垚MySQL涔辩爜锛?
鈼?MySQL鍒涘缓琛ㄦ椂娣诲姞瀛楁鏄彲浠ラ€夋嫨缂栫爜鐨?濡傛灉杩欑缂栫爜涓庝綘鐨勭綉椤电紪鐮佷笉涓€鑷?涔熷彲鑳介€犳垚MySQL涔辩爜锛?
鈼?鐢ㄦ埛鎻愪氦椤甸潰鐨勭紪鐮佷笌鏄剧ず鏁版嵁鐨勯〉闈㈢紪鐮佷笉涓€鑷?灏辫偗瀹氫細閫犳垚PHP椤甸潰涔辩爜锛?
鈼?濡傜敤鎴疯緭鍏ヨ祫鏂欑殑椤甸潰鏄痓ig5鐮? 鏄剧ず鐢ㄦ埛杈撳叆鐨勯〉闈㈠嵈鏄痝b2312,杩欑100%浼氶€犳垚PHP椤甸潰涔辩爜锛?
鈼?PHP椤甸潰瀛楃闆嗕笉姝g‘锛?
鈼?PHP杩炴帴MySQL鏁版嵁搴撹鍙ユ寚瀹氱殑缂栫爜涓嶆纭€?
娉ㄦ剰锛?
寰堝浜洪兘鎬€鐤慚ySQL鐗堟湰涓嶄竴鑷翠細瀵艰嚧涔辩爜,鐩镐俊鐪嬩簡鏈鏄庝綘灏变笉浼氳繖鏍疯涓轰簡銆?
骞虫椂浣犲湪鏌愪簺缃戠珯鐪嬪埌鐨勬枃瀛楀彲鑳芥湁鍑犵缂栫爜, 濡備綘鐪嬪埌涓€涓箒浣撳瓧,瀹冩湁鍙兘鏄痓ig5缂栫爜,涔熸湁 鍙兘鏄痷tf-8缂栫爜鐨?鏇存湁鍙兘鏄痝b鐮佺殑,娌¢敊,涔熷氨鏄鏈夌畝浣撶紪鐮佺殑绻佷綋瀛?涔熸湁绻佷綋缂栫爜鐨勭畝浣撳瓧,涓€瀹氳浜嗚В杩欎竴鐐广€?
濡傛灉浣犳槸鍋氫竴涓畝浣撶紪鐮佺殑缃戦〉,缂栫爜瀹氫负GB2312,濡傛灉鏈夐娓拰鍙版咕鍦板尯鐨勮瀹㈡彁浜ょ箒浣撶殑淇℃伅,灏卞彲鑳戒細閫犳垚涔辩爜,瑙e喅鏂规硶锛?
灏嗙綉绔欑紪鐮佽涓?utf-8,杩欐牱鍙互鍏煎涓栫晫涓婃墍鏈夊瓧绗︺€?
濡傛灉缃戠珯宸茬粡杩愪綔浜嗗ソ涔?宸叉湁寰堝鏃ф暟鎹?涓嶈兘鍐嶆洿鏀圭畝浣撲腑鏂囩殑璁惧畾,閭d箞寤鸿灏嗛〉闈㈢殑缂栫爜璁句负 GBK, GBK涓嶨B2312鐨勫尯鍒氨鍦ㄤ簬:GBK鑳芥瘮GB2312鏄剧ず鏇村鐨勫瓧绗?瑕佹樉绀虹畝浣撶爜鐨勭箒浣撳瓧,灏卞彧鑳界敤GBK銆?
浣跨敤MySQL+PHP浜х敓涔辩爜鐨勫師鍥犻兘浜嗚В寰楀緢娓呮浜?閭d箞瑙e喅灏变笉鍥伴毦浜嗐€?
MySQL+PHP浜х敓涔辩爜鐨勮В鍐冲姙娉曪細
濡傛灉瀹夎MySQL鐨勭紪鐮佸凡涓嶈兘鏇存敼,寰堝鏈嬪弸鏄喘涔拌櫄鎷熶富鏈哄缓绔嬬綉绔?鏃犳潈鏇存敼MySQL鐨勫畨瑁呯紪鐮?杩欎竴鍏虫垜浠彲浠ヨ烦杩?鍥犱负鍙鍚庨潰鐨勬鑱氭纭?涓€鏍疯兘瑙e喅涔辩爜闂銆?
淇敼鏁版嵁搴撶紪鐮侊紝濡傛灉鏄暟鎹簱缂栫爜涓嶆纭?鍙互鍦≒HPmyadmin 鎵ц濡備笅鍛戒护锛?
ALTER DATABASE 'test' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
浠ヤ笂鍛戒护灏辨槸灏唗est鏁版嵁搴撶殑缂栫爜璁句负utf8銆?
淇敼琛ㄧ殑缂栫爜锛?
ALTER TABLE 'category' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
浠ヤ笂鍛戒护灏辨槸灏嗕竴涓〃category鐨勭紪鐮佹敼涓簎tf8銆?
淇敼瀛楁鐨勭紪鐮侊細
ALTER TABLE 'test' CHANGE 'dd' 'dd' VARCHAR( 45 ) CHARACTER
SET utf8 COLLATE utf8_bin NOT NULL
浠ヤ笂鍛戒护灏辨槸灏唗est琛ㄤ腑dd鐨勫瓧娈电紪鐮佹敼涓簎tf8銆?
濡傛灉鏄繖绉嶆儏鍐靛鏄撹В鍐筹紝鍙渶妫€鏌ヤ笅椤甸潰锛屼慨鏀规簮鏂囦欢鐨刢harset鍗冲彲銆?
杩欑鎯呭喌涔熸槸淇敼椤甸潰charset鍗冲彲銆?
鍦ㄨ繛鎺ユ暟鎹簱鐨勮鍙ヤ腑銆?
mysql_connect('localhost','user','password');
mysql_select_db('my_db');
mysql_query("set names utf8;"); //select 鏁版嵁搴撲箣鍚庡姞澶氳繖涓€鍙?
涓轰簡閬垮厤PHP椤甸潰涔辩爜鐨勫彂鐢燂紝PHP椤甸潰寮€濮嬬涓€鍙?
header("content-type:text/html; charset=utf-8");
//寮鸿鎸囧畾椤甸潰鐨勭紪鐮侊紝浠ラ伩鍏嶄贡鐮?
娉ㄦ剰锛氱収浠ヤ笂鏂规硶淇敼浠ュ悗鍙兘淇濊瘉浣犳柊鎻掑叆鐨勬暟鎹笉浼氫贡鐮?涓句釜渚?濡傛灉浣犵敤鎴峰凡鎻愪氦鐨勬暟鎹槸BIG5,浣犲嵈鎯抽€氳繃浠ヤ笂鏂规硶鏀逛负鍙互鍦℅B2312鐨勭綉椤垫纭樉绀烘槸涓嶅彲鑳界殑, 杩欑鏂囧瓧鍐呯爜鐨勫彉鎹㈠彧鑳介€氳繃鍙﹀啓绋嬪簭鏉ヨВ鍐炽€?