PHPä¸MYSQLæé åºç°ä¸æä¹±ç çâç»æâ解å³æ¹æ¡
PHPç¨åºè®¾è®¡ä¸ä¸æç¼ç é®é¢æ¾ç»å°æ°å¾å¤äººï¼å¯¼è´è¿ä¸ªé®é¢çåå å ¶å®å¾ç®åï¼æ¯ä¸ªå½å®¶(æåºå)é½è§å®äºè®¡ç®æºä¿¡æ¯äº¤æ¢ç¨çå符ç¼ç éï¼å¦ç¾å½çæ©å± ASCII ç , ä¸å½ç GB2312-80ï¼æ¥æ¬ç JIS çãä½ä¸ºè¯¥å½å®¶/åºåå ä¿¡æ¯å¤ççåºç¡ï¼å符ç¼ç éèµ·çç»ä¸ç¼ç ç
PHPç¨åºè®¾è®¡ä¸ä¸æç¼ç é®é¢æ¾ç»å°æ°å¾å¤äººï¼å¯¼è´è¿ä¸ªé®é¢çåå å ¶å®å¾ç®åï¼æ¯ä¸ªå½å®¶(æåºå)é½è§å®äºè®¡ç®æºä¿¡æ¯äº¤æ¢ç¨çå符ç¼ç éï¼å¦ç¾å½çæ©å± ASCII ç , ä¸å½ç GB2312-80ï¼æ¥æ¬ç JIS çãä½ä¸ºè¯¥å½å®¶/åºåå ä¿¡æ¯å¤ççåºç¡ï¼å符ç¼ç éèµ·çç»ä¸ç¼ç çéè¦ä½ç¨ãå符ç¼ç éæé¿åº¦å为 SBCS(ååèå符é)ï¼DBCS(ååèå符é)两大类ãæ©æç软件(å°¤å ¶æ¯æä½ç³»ç»)ï¼ä¸ºäºè§£å³æ¬å°å符信æ¯ç计ç®æºå¤çï¼åºç°äºåç§æ¬å°åçæ¬ (L10N)ï¼ä¸ºäºåºåï¼å¼è¿äº LANG, Codepage çæ¦å¿µãä½æ¯ç±äºå个æ¬å°å符é代ç èå´éå ï¼ç¸äºé´ä¿¡æ¯äº¤æ¢å°é¾; 软件å个æ¬å°åçæ¬ç¬ç«ç»´æ¤ææ¬è¾é«ãå æ¤æå¿ è¦å°æ¬å°åå·¥ä½ä¸çå ±æ§æ½ååºæ¥ï¼ä½ä¸è´å¤çï¼å°ç¹å«çæ¬å°åå¤çå 容éä½å°æå°ãè¿ä¹å°±æ¯æè°çå½é å (118N)ãåç§è¯è¨ä¿¡æ¯è¢«è¿ä¸æ¥è§è为 Locale ä¿¡æ¯ãå¤ççåºå±å符éåæäºå ä¹å å«äºææåå½¢ç Unicodeãããç°å¨å¤§é¨åå ·æå½é åç¹å¾çè½¯ä»¶æ ¸å¿å符å¤çé½æ¯ä»¥ Unicode 为åºç¡çï¼å¨è½¯ä»¶è¿è¡æ¶æ ¹æ®å½æ¶çocale/Lang/Codepage 设置确å®ç¸åºçæ¬å°å符ç¼ç 设置ï¼å¹¶ä¾æ¤å¤çæ¬å°å符ãå¨å¤çè¿ç¨ä¸éè¦å®ç° Unicode åæ¬å°å符éçç¸äºè½¬æ¢ï¼çæ以 Unicode 为ä¸é´ç两个ä¸åæ¬å°å符éçç¸äºè½¬æ¢ãè¿ç§æ¹å¼å¨ç½ç»ç¯å¢ä¸è¢«è¿ä¸æ¥å»¶ä¼¸ï¼ä»»ä½ç½ç»ä¸¤ç«¯çå符信æ¯ä¹éè¦æ ¹æ®å符éç设置转æ¢æå¯æ¥åçå 容ã
ããæ°æ®åºä¸çå符éç¼ç é®é¢ ããæµè¡çå
³ç³»æ°æ®åºç³»ç»é½æ¯ææ°æ®åºå符éç¼ç ï¼ä¹å°±æ¯è¯´å¨å建æ°æ®åºæ¶å¯ä»¥æå®å®èªå·±çå符é设置ï¼æ°æ®åºçæ°æ®ä»¥æå®çç¼ç å½¢å¼åå¨ãå½åºç¨ç¨åºè®¿é®æ°æ®æ¶ï¼å¨å
¥å£ååºå£å¤é½ä¼æå符éç¼ç ç转æ¢ã对äºä¸ææ°æ®ï¼æ°æ®åºå符ç¼ç ç设置åºå½ä¿è¯æ°æ®çå®æ´æ§ãGB2312ãGBKãUTF-8 çé½æ¯å¯éçæ°æ®åºå符éç¼ç ; å½ç¶æ们ä¹å¯ä»¥éæ© ISO8859-1 (8-bit)ï¼åªæ¯æ们å¾å¨åºç¨ç¨åºåæ°æ®ä¹åå
å°
16Bit çä¸ä¸ªæ±åæ Unicode æåæ两个 8-bit çå符ï¼è¯»æ°æ®ä¹åä¹éè¦å°ä¸¤ä¸ªåèå并起æ¥ï¼åæ¶è¿è¦å¤å«å
¶ä¸ç SBCS å符ï¼å æ¤æ们并ä¸æ¨èéç¨ ISO8859-1 ä½ä¸ºæ°æ®åºå符éç¼ç ãè¿æ ·ä¸ä½æ²¡æå
åå©ç¨æ°æ®åºèªèº«çå符éç¼ç æ¯æï¼èä¸åæ¶ä¹å¢å äºç¼ç¨çå¤æ度ãç¼ç¨æ¶ï¼å¯ä»¥å
ç¨æ°æ®åºç®¡çç³»ç»æä¾ç管çåè½æ£æ¥å
¶ä¸çä¸ææ°æ®æ¯å¦æ£ç¡®ã
ããPHP ç¨åºå¨æ¥è¯¢æ°æ®åºä¹åï¼é¦å
æ§è¡ mysql_query("SET NAMES xxxx"); å
¶ä¸ xxxx æ¯ä½ ç½é¡µçç¼ç (charset=xxxx)ï¼å¦æç½é¡µä¸ charset=utf8ï¼å xxxx=utf8ï¼å¦æç½é¡µä¸ charset=gb2312ï¼åxxxx=gb2312ï¼å ä¹ææ WEB ç¨åºï¼é½æä¸æ®µè¿æ¥æ°æ®åºçå
Œ
±ä»£ç ï¼æ¾å¨ä¸ä¸ªæ件éï¼å¨è¿æ件éï¼å å
¥ mysql_query("SET NAMES xxxx") å°±å¯ä»¥äºã
ããSET NAMES æ¾ç¤ºå®¢æ·ç«¯åéç SQL è¯å¥ä¸ä½¿ç¨ä»ä¹å符éãå æ¤ï¼SET NAMES 'utf-8' è¯å¥åè¯æå¡å¨âå°æ¥ä»è¿ä¸ªå®¢æ·ç«¯ä¼ æ¥çä¿¡æ¯éç¨å符é utf-8âãå®è¿ä¸ºæå¡å¨åéå客æ·ç«¯çç»ææå®äºå符é(ä¾å¦ï¼å¦æä½ ä½¿ç¨ä¸ä¸ª SELECT è¯å¥ï¼å®è¡¨ç¤ºå值使ç¨äºä»ä¹å符é)ã
å®ä½é®é¢æ¶å¸¸ç¨çæå·§ :
ããå®ä½ä¸æç¼ç é®é¢é常éç¨æ笨çä¹æ¯æææçåæ³âå¨ä½ 认为æå«ççç¨åºå¤çåæå°å符串çå
ç ãéè¿æå°å符串çå
ç ï¼ä½ å¯ä»¥åç°ä»ä¹æ¶åä¸æå符被转æ¢æ Unicodeï¼ä»ä¹æ¶åUnicode 被转åä¸æå
ç ï¼ä»ä¹æ¶åä¸ä¸ªä¸æåæäºä¸¤ä¸ª Unicode å符ï¼ä»ä¹æ¶åä¸æå符串被转æäºä¸ä¸²é®å·ï¼ä»ä¹æ¶åä¸æå符串çé«ä½è¢«æªæäºâ¦â¦
åç¨åéçæ ·æ¬å符串ä¹æå©äºåºåé®é¢çç±»åãå¦ï¼"aaå aa?@aa" çä¸è±ç¸é´ï¼GBãGBKç¹å¾å符åæçå符串ãä¸è¬æ¥è¯´ï¼è±æå符æ 论æä¹è½¬æ¢æå¤çï¼é½ä¸ä¼å¤±ç(å¦æéå°äºï¼å¯ä»¥å°è¯çå¢å è¿ç»çè±æåæ¯é¿åº¦)ã
ãã解å³åç§åºç¨çä¹±ç é®é¢
åæ ·ä¹çæä¸ä¸ªé®é¢ï¼ä¸ºä»ä¹åè
å°±ç»å¯¹èµ·ä½ç¨ï¼èåè
ææ¶åå°±ä¸è¡å¢?è¿å°±æ¯æ¥ä¸æ¥è¦è°çApache çåå äºã
ãã3) AddDefaultCharset ããApache æ ¹ç®å½ç conf æ件夹éï¼ææ´ä¸ª Apache çé
ç½®ææ¡£ httpd.confãããç¨ææ¬ç¼è¾å¨æå¼ httpd.confï¼ç¬¬ 708 è¡(ä¸åçæ¬å¯è½ä¸å)æ AddDefaultCharset xxxï¼xxx为ç¼ç å称ãè¿è¡ä»£ç çææï¼è®¾ç½®æ´ä¸ªæå¡å¨å
çç½é¡µæ件 http æ 头éçå符éä¸ºä½ é»è®¤ç xxxå符éãæè¿è¡ï¼å°±ç¸å½äºç»æ¯ä¸ªæ件é½å äºä¸è¡ header("content-type:text/html; charset=xxx")ãè¿ä¸å°±æç½ä¸ºä»ä¹ææ设置äºæ¯
utf-8ï¼å¯æµè§å¨å§ç»éç¨ gb2312 çåå ã
ããä¸é¢ååºä»¥ä¸çä¼å 顺åºï¼ãã.. header("content-type:text/html; charset=xxx") .WVEãã.. AddDefaultCharset xxx
ãã..ããå¦æä½ æ¯ web ç¨åºåï¼å»ºè®®ç»ä½ çæ¯ä¸ªé¡µé¢é½å 个header("content-type:text/html; charset=xxx")ï¼è¿æ ·å°±å¯ä»¥ä¿è¯å®å¨ä»»ä½æå¡å¨é½è½æ£ç¡®æ¾ç¤ºï¼å¯ç§»æ¤æ§ä¹æ¯è¾å¼ºã
ãã4) php.ini ä¸ç default_charset é ç½®ï¼ããphp.ini ä¸ç default_charset = "gb2312" å®ä¹äº php çé»è®¤è¯è¨å符éãä¸è¬æ¨è注éææ¤è¡ï¼è®©æµè§å¨æ ¹æ®ç½é¡µå¤´ä¸ç charset æ¥èªå¨éæ©è¯è¨èéåä¸ä¸ªå¼ºå¶æ§çè§å®ï¼è¿æ ·å°±å¯ä»¥å¨åå°æå¡å¨ä¸æä¾å¤ç§è¯è¨çç½é¡µæå¡ã
ããç»æè¯
ããå ¶å® php å¼åä¸çä¸æç¼ç 并没ææ³åçé£ä¹å¤æï¼è½ç¶å®ä½å解å³é®é¢æ²¡æå®è§ï¼åç§è¿è¡ç¯å¢ä¹åä¸å°½ç¶ï¼ä½åé¢çåçæ¯ä¸æ ·çãäºè§£å符éçç¥è¯æ¯è§£å³å符é®é¢çåºç¡ãä¸è¿ï¼éçä¸æå符éçååï¼ä¸ä» ä» æ¯ php ç¼ç¨ï¼ä¸æä¿¡æ¯å¤çä¸çé®é¢è¿æ¯ä¼åå¨ä¸æ®µæ¶é´çã
è¦è¯´mysqlä¹±ç ï¼å¾å ä»mysqlçå 个åæ°è¯´èµ·ï¼ä»mysql5å¼å§ï¼å¤äºå 个设置å符éçç³»ç»åéï¼
character_set_client 客æ·ç«¯å符é
character_set_connection 客æ·ç«¯ä¸æå¡å¨ç«¯è¿æ¥éç¨çå符é
character_set_results SELECTæ¥è¯¢è¿åæ°æ®çå符é
character_set_database æ°æ®åºéç¨çå符é
ä¹±ç é®é¢ä¸è¬æ¯ç±äºä»¥ä¸å 个åé设置é误ç
§æçï¼å¾å¤äººå¨è¯·æä¹±ç é®é¢çæ¶åï¼ä¸è¬é½ä¼å¾å°ä¸ä¸ªè¿æ ·ççæ¡ï¼âä½ å
set namesä¸ä¸âãé£ä¹set namesæ¯ä»ä¹å¢ï¼ set nameså®é
ä¸å°±æ¯åæ¶è®¾ç½®äºcharacter_set_client, character_set_connection, character_set_resultsè¿ä¸ä¸ªç³»ç»åéã
ä¾å¦set names 'gbk'çåäºï¼
set @@character_set_client = 'gbk'
set @@character_set_connection = 'gbk'
set @@character_set_results = 'gbk'
å¾å¤æ åµä¸ï¼è¿æ ·è®¾ç½®äºä¹åå°±è½æä¹±ç é®é¢è§£å³äºãä½æ¯è¿æ¯ä¸è½å®å ¨é¿å åºç°ä¹±ç çå¯è½ï¼ä¸ºä»ä¹å¢ï¼
å 为character_set_client,character_set_connectionè¿ä¸¤ä¸ªåéä» ç¨äºä¿è¯ä¸character_set_databaseç¼ç çä¸è´ï¼ècharacter_set_resultsåç¨ä¸ä¿è¯SELECTè¿åçç»æä¸ç¨åºçç¼ç ä¸è´ã
ä¾å¦ï¼ä½ çæ°æ®åº(character_set_database)ç¨çæ¯utf8çå符éï¼é£ä¹ä½ å°±è¦ä¿è¯character_set_client,character_set_connectionä¹æ¯utf8çå符éãèä½ çç¨åºä¹è®¸éç¨ç并ä¸æ¯utf8ï¼æ¯å¦ä½ çç¨åºç¨çæ¯gbkï¼é£ä¹ä½ è¥æcharacter_set_resultsä¹è®¾ç½®ä¸ºutf8çè¯å°±ä¼åºç°ä¹±ç é®é¢ãæ¤æ¶ä½ åºè¯¥æcharacter_set_results设置为gbkãè¿æ ·å°±è½ä¿è¯æ°æ®åºè¿åçç»æä¸ä½ çç¨åºçç¼ç ä¸è´ã
ä¸é¢æç»åºä¸æ®µç¨äºè®¾ç½®å符éç代ç (å ¶ä¸ç¨å°äºä¸ä¸ªæèªå·±åçdbåºï¼ç¸ä¿¡åºè¯¥ä¸å½±åé 读)ï¼
//å设æ们çç¨åºéç¨çæ¯utf8çå符é
$program_char='utf8';
//å æ£æ¥mysqlççæ¬å·ï¼å¦æçæ¬å·å¤§äº4æ们æå¯ä»¥è®¾ç½®è¿äºç³»ç»åé(mysql4è¿æ²¡æè¿äºç³»ç»åé)
$version=current($db->fetch_one('SELECT VERSION()'));
if(substr($version,0,1) >4)
{
//ååºå½åæ°æ®åºçå符é
$sql='SELECT @@character_set_database';
$char=current($db->fetch_one($sql));
//å°å®¢æ·ç«¯å符é(character_set_client)åè¿æ¥å符é(character_set_connection)设置为ä¸æ°æ®åºå符é(character_set_database)ä¸è´
$db->query('SET @@character_set_client = "'.$char.'"');
$db->query('SET @@character_set_connection = "'.$char.'"');
//å°SELECTæ¥è¯¢è¿åæ°æ®çå符é设置为ä¸å½åç¨åºçå符éä¸è´
$db->query('SET @@character_set_results = "'.$program_char.'"');
}
?>
1ãè¦ä¿è¯æ°æ®åºä¸åçæ°æ®ä¸æ°æ®åºç¼ç ä¸è´ï¼å³æ°æ®ç¼ç ä¸character_set_databaseä¸è´ï¼
2ãè¦ä¿è¯é讯çå符éä¸æ°æ®åºçå符éä¸è´ï¼å³character_set_client, character_set_connectionä¸character_set_databaseä¸è´ï¼
3ãè¦ä¿è¯SELECTçè¿åä¸ç¨åºçç¼ç ä¸è´ï¼å³character_set_resultsä¸ç¨åºç¼ç ä¸è´ï¼
4ãè¦ä¿è¯ç¨åºç¼ç ä¸æµè§å¨ç¼ç ä¸è´ï¼å³ç¨åºç¼ç ä¸ä¸è´ã
è§£å³ mysql ä¸æä¹±ç çç»ææ¹æ¡
I promise this is gonna be the last time on it
èªä»åå®ä¸é¢ä¸¤ç¯æç« ï¼
wordpress 1.5å级注æäºé¡¹-ä¸æä¹±ç ç¯
MySQL(åPHPæé
ä¹æä½³ç»å) 4.1ä¸æä¹±ç 第äºå»
~
è¿å»å 个æå°±ä¸æææ¥ä¿¡è¯¢é®åç§MySQL(åPHPæé
ä¹æä½³ç»å)ä¸æç¸å®¹çé®é¢ï¼æ以ææºä¼çå°è®¸å¤ç©å®¶ä»¬ç¨çåå¼è¿æ¥æ³ä¸ç¨å¼ï¼å®å¨å¤ªå¼眼çã
æè¿å 为转æ¢å°flex 2å为å¼åå¹³å°å¹¶éåä¸äºäº§åï¼è®¸å¤å»å¹´åçframeworkå°±æ æ³ä½¿ç¨ï¼èå
¶ä¸æé¨ä»½ä¸é¨å¤çå¤å½è¯ç³»çlibraryä¹éä¹å¤±æï¼å¯¼è´æå¾éæ°é¢å¯¹è¿ä¸ªé®é¢ï¼æ以æ£å¥½ç±æ¤æºä¼å°ä¸äºæ°å¿å¾æ´çåºæ¥ã
ï¼MySQL(åPHPæé
ä¹æä½³ç»å)ä¸æä¹±ç çåå
MySQL(åPHPæé
ä¹æä½³ç»å)ä¼åºç°ä¸æä¹±ç çåå ä¸å¤ä¹ä¸åå ç¹ï¼
-MySQL(åPHPæé
ä¹æä½³ç»å) serveræ¬èº«è®¾å®é®é¢ï¼ä¾å¦è¿åçå¨latin1
-MySQL(åPHPæé
ä¹æä½³ç»å) tableçè¯ç³»è®¾å®é®é¢(å
å«characterä¸collation)
-客æ·ç«¯ç¨å¼(ä¾å¦php)çè¿çº¿è¯ç³»è®¾å®é®é¢
å¨ä¹åç两ç¯æç« ä¸å·²ä»ç»è¿å¦ä½è®¾å®MySQL(åPHPæé
ä¹æä½³ç»å) server/tableçcharacter/collationã
æ¥ä¸æ¥åªéè¦è¡¥å
å ç¹æ³¨æäºï¼
ï¼MySQL(åPHPæé
ä¹æä½³ç»å)ä¸æä¹±ç å¿
è解å³æ³
1ãMySQL(åPHPæé
ä¹æä½³ç»å)å¯å¨æ¶ä¼è¯»åä¸ä¸ªé¢è®¾çconfigæ¡£ï¼ä¸è¬å称为my.iniï¼èå®ä¼å°ä¸å两ä½ç½®å»å¯»æ¾è¿ä¸ªæ¡£æ¡ï¼
C:\windows\my.iniä¹å°±æ¯ä½ä¸ç³»ç»çå®è£
ç®å½ï¼ä¹æå¯è½æ¯C:\winnt\my.ini
C:\:my.cnfä¹å°±æ¯C diskçæ ¹ç®å½
注æä¸åä½ç½®éçæ¡£æ¡suffix(åç¼)ä¸ä¸æ ·ï¼è¿ç¹å¨ä¹åçæç« ä¸æ²¡æç¹å«å¼ºè°ï¼å æ¤é£æ¶ææ¯ç¨æ´å¤æçæ¹æ³ç´æ¥éæ°å°MySQL(åPHPæé
ä¹æä½³ç»å)注åå°serviceéé¢ï¼å¹¶å¨é£éæå®my.iniçä½ç½®ã
2ãmy.iniéçå
容为ï¼
[MySQL(åPHPæé
ä¹æä½³ç»å)d]
default-character-set=utf8
[client]
default-character-set=utf8
init_connect='SET NAMES utf8'
å
¶ä¸MySQL(åPHPæé
ä¹æä½³ç»å)dæ¯æå®serverå¯å¨æ¶è¦ç¨çè¯ç³»ï¼ä½å¦æè¿é设å®ä¸ºutf8å¯è½ä¼è®©è®¸å¤è±æ软ä½ä¸å¼å¿ï¼ä¾å¦osCommerce/mediaWikiï¼æ以è¿é建议设ælatin1ã
ä¸é¢çclientåæ¯è®¾å®å½clientè¿çº¿æ¶è¦ä½¿ç¨ä»ä¹è¯ç³»ï¼ä½å¯æçæ¯è¿ä¸ªè®¾å®ä¸æ¯æ¯ä¸ªclienté½ä¼é¸å®ï¼åºæ¬ä¸åªæMySQL(åPHPæé
ä¹æä½³ç»å)èªå·²å®¶çç¨å¼ï¼ä¾å¦MySQL(åPHPæé
ä¹æä½³ç»å).exe, MySQL(åPHPæé
ä¹æä½³ç»å)d.exe, MySQL(åPHPæé
ä¹æä½³ç»å)admin.exeææ¯MySQL(åPHPæé
ä¹æä½³ç»å) Control Centerè¿ç§ç¨å¼ä¼å»è¯»åè¿ä¸ªè®¾å®æ¡£ç¶åæ¹ç¨utf8è¿çº¿ã
note:æè°¢b6sæ¡çæ
ç¸å©æä¾ç¬¬äºè¡æ令ï¼æ®è¯´æ¯ä¸æ¯æ¯phpç¨å¼å»è®¾å®connection settingæ´å¿«ï¼è¿æ ·åºè¯¥ä¹å¯ä»¥é¡ºä¾¿è§£å³phpmyadminæ æ³æ£ç¡®æ¾ç¤ºunicodeä¸æçé®é¢(ä¸è¿amfphpå°æ¯ä¸åè¿å¥ï¼ä¸å®è¦ä¹ä¹çèªå·²è®¾å®è¯ç³»æè¡)
ä½å¤§é¨ä»½å·¥ç¨å¸åºè¯¥é½æ¯èªå·²åphp/jsp(SUNä¼ä¸çº§åºç¨çé¦é)ç¨å¼å»è¿çº¿ï¼æ¤æ¶èªç¶ä¸ä¼è¯»åè¿ä¸ªè®¾å®è继ç»ä½¿ç¨é¢è®¾çè¯ç³»- latin1ã
è¿ä¹æ£æ¯å
«ææ¥ä¿¡æåéµäº¡çå°æ¹ã
é常æä¼ç¨ä¸ä¸ªç¬ç«çæ¡£æ¡æ¥å¤çMySQL(åPHPæé
ä¹æä½³ç»å) connectionç设å®ï¼ä¾å¦ï¼
PLAIN TEXT
//database connection details.
$host = "localhost";
$link = MySQL(åPHPæé
ä¹æä½³ç»å)_connect($host, "xxx", "xxx");
MySQL(åPHPæé
ä¹æä½³ç»å)_query("SET NAMES 'utf8'");
MySQL(åPHPæé
ä¹æä½³ç»å)_select_db("your_table_name_here", $link);
?>
请注æå¨MySQL(åPHPæé
ä¹æä½³ç»å)_connectå第äºè¡çå°æ¹æå ä¸ä¸ä¸ª"set names 'utf8' "çæ令ï¼åè¯MySQL(åPHPæé
ä¹æä½³ç»å)è¿ä¸ªconnectionä¹åçè¿çº¿å
容é½è¦ä½¿ç¨utf8ï¼ç»è¿è¿æ ·è®¾å®åï¼é常就å¯ä»¥è§£å³å¤§é¨ä»½é®é¢ã
ä»è¿éä¹å¯ä»¥æ¨æ³å¾ç¥ï¼å¦æä½ æç¨æç§custom connection poolingæºå¶ï¼å°±è¦è®°å¾å¨æ¯æ¬¡å»ºç«æ°çconnectionåç«å³è®¾å®ä¸ºutf8ã
è¿ç»è®¾å®ç»è¿å 天çåè¦æµè¯(使ç¨ä¸æç¹ãç®ãæ¥æãé©æ)åå·²ç»è¯å®å®å
¨ä¸ä¼æä¹±ç ææ¯æäºååæ"å£"ã
ä¾åï¼è¯è
è¾å
¥è¿å 个åãä¸éå¯å¦å°ãå¦æå®ä»¬è½æ£ç¡®è¿å
¥MySQL(åPHPæé
ä¹æä½³ç»å)å被读åºæ¥ï¼é£å°±æ¯ä¸æ没é®é¢äºï¼å¦æ读åºæ¥ååæãå£ãåé£å°±æ¯é©å½è¿æªæååå¿ä»éåªå...orz
å½ç¶æä¹é¡ºä¾¿éªè¯äºflex2 - amfphp - php - MySQL(åPHPæé
ä¹æä½³ç»å)æ¥åä¼ resultsetä¹ä¸åä¼æä¸æä¹±ç é®é¢ï¼å¯ä»¥å®å¿ä½¿ç¨å°ã
è§£å³ mysql ä¸æä¹±ç çç»ææ¹æ¡
I promise this is gonna be the last time on it
èªä»åå®ä¸é¢ä¸¤ç¯æç« ï¼
wordpress 1.5å级注æäºé¡¹-ä¸æä¹±ç ç¯
MySQL 4.1ä¸æä¹±ç 第äºå»
~
è¿å»å 个æå°±ä¸æææ¥ä¿¡è¯¢é®åç§MySQLä¸æç¸å®¹çé®é¢ï¼æ以ææºä¼çå°è®¸å¤ç©å®¶ä»¬ç¨çåå¼è¿æ¥æ³ä¸ç¨å¼ï¼å®å¨å¤ªå¼眼çã
æè¿å 为转æ¢å°flex 2å为å¼åå¹³å°å¹¶éåä¸äºäº§åï¼è®¸å¤å»å¹´åçframeworkå°±æ æ³ä½¿ç¨ï¼èå
¶ä¸æé¨ä»½ä¸é¨å¤çå¤å½è¯ç³»çlibraryä¹éä¹å¤±æï¼å¯¼è´æå¾éæ°é¢å¯¹è¿ä¸ªé®é¢ï¼æ以æ£å¥½ç±æ¤æºä¼å°ä¸äºæ°å¿å¾æ´çåºæ¥ã
ï¼MySQLä¸æä¹±ç çåå
MySQLä¼åºç°ä¸æä¹±ç çåå ä¸å¤ä¹ä¸åå ç¹ï¼
-MySQL serveræ¬èº«è®¾å®é®é¢ï¼ä¾å¦è¿åçå¨latin1
-MySQL tableçè¯ç³»è®¾å®é®é¢(å
å«characterä¸collation)
-客æ·ç«¯ç¨å¼(ä¾å¦php)çè¿çº¿è¯ç³»è®¾å®é®é¢
å¨ä¹åç两ç¯æç« ä¸å·²ä»ç»è¿å¦ä½è®¾å®MySQL server/tableçcharacter/collationã
æ¥ä¸æ¥åªéè¦è¡¥å
å ç¹æ³¨æäºï¼
ï¼MySQLä¸æä¹±ç å¿
è解å³æ³
1ãMySQLå¯å¨æ¶ä¼è¯»åä¸ä¸ªé¢è®¾çconfigæ¡£ï¼ä¸è¬å称为my.iniï¼èå®ä¼å°ä¸å两ä½ç½®å»å¯»æ¾è¿ä¸ªæ¡£æ¡ï¼
C:\windows\my.iniä¹å°±æ¯ä½ä¸ç³»ç»çå®è£
ç®å½ï¼ä¹æå¯è½æ¯C:\winnt\my.ini
C:\:my.cnfä¹å°±æ¯C diskçæ ¹ç®å½
注æä¸åä½ç½®éçæ¡£æ¡suffixä¸ä¸æ ·ï¼è¿ç¹å¨ä¹åçæç« ä¸æ²¡æç¹å«å¼ºè°ï¼å æ¤é£æ¶ææ¯ç¨æ´å¤æçæ¹æ³ç´æ¥éæ°å°MySQL注åå°serviceéé¢ï¼å¹¶å¨é£éæå®my.iniçä½ç½®ã
2ãmy.iniéçå
容为ï¼
[MySQLd]
default-character-set=utf8
[client]
default-character-set=utf8
init_connect='SET NAMES utf8'
å
¶ä¸MySQLdæ¯æå®serverå¯å¨æ¶è¦ç¨çè¯ç³»ï¼ä½å¦æè¿é设å®ä¸ºutf8å¯è½ä¼è®©è®¸å¤è±æ软ä½ä¸å¼å¿ï¼ä¾å¦osCommerce/mediaWikiï¼æ以è¿é建议设ælatin1ã
ä¸é¢çclientåæ¯è®¾å®å½clientè¿çº¿æ¶è¦ä½¿ç¨ä»ä¹è¯ç³»ï¼ä½å¯æçæ¯è¿ä¸ªè®¾å®ä¸æ¯æ¯ä¸ªclienté½ä¼é¸å®ï¼åºæ¬ä¸åªæMySQLèªå·²å®¶çç¨å¼ï¼ä¾å¦MySQL.exe, MySQLd.exe, MySQLadmin.exeææ¯MySQL Control Centerè¿ç§ç¨å¼ä¼å»è¯»åè¿ä¸ªè®¾å®æ¡£ç¶åæ¹ç¨utf8è¿çº¿ã
note:æè°¢b6sæ¡çæ
ç¸å©æä¾ç¬¬äºè¡æ令ï¼æ®è¯´æ¯ä¸æ¯æ¯phpç¨å¼å»è®¾å®connection settingæ´å¿«ï¼è¿æ ·åºè¯¥ä¹å¯ä»¥é¡ºä¾¿è§£å³phpmyadminæ æ³æ£ç¡®æ¾ç¤ºunicodeä¸æçé®é¢(ä¸è¿amfphpå°æ¯ä¸åè¿å¥ï¼ä¸å®è¦ä¹ä¹çèªå·²è®¾å®è¯ç³»æè¡)
ä½å¤§é¨ä»½å·¥ç¨å¸åºè¯¥é½æ¯èªå·²åphp/jsp(SUNä¼ä¸çº§åºç¨çé¦é)ç¨å¼å»è¿çº¿ï¼æ¤æ¶èªç¶ä¸ä¼è¯»åè¿ä¸ªè®¾å®è继ç»ä½¿ç¨é¢è®¾çè¯ç³»- latin1ã
è¿ä¹æ£æ¯å
«ææ¥ä¿¡æåéµäº¡çå°æ¹ã
é常æä¼ç¨ä¸ä¸ªç¬ç«çæ¡£æ¡æ¥å¤çMySQL connectionç设å®ï¼ä¾å¦ï¼
PLAIN TEXT
//database connection details.
$host = "localhost";
$link = MySQL_connect($host, "xxx", "xxx");
MySQL_query("SET NAMES 'utf8'");
MySQL_select_db("your_table_name_here", $link);
?>
请注æå¨MySQL_connectå第äºè¡çå°æ¹æå ä¸ä¸ä¸ª"set names 'utf8' "çæ令ï¼åè¯MySQLè¿ä¸ªconnectionä¹åçè¿çº¿å
容é½è¦ä½¿ç¨utf8ï¼ç»è¿è¿æ ·è®¾å®åï¼é常就å¯ä»¥è§£å³å¤§é¨ä»½é®é¢ã
ä»è¿éä¹å¯ä»¥æ¨æ³å¾ç¥ï¼å¦æä½ æç¨æç§custom connection poolingæºå¶ï¼å°±è¦è®°å¾å¨æ¯æ¬¡å»ºç«æ°çconnectionåç«å³è®¾å®ä¸ºutf8ã
è¿ç»è®¾å®ç»è¿å 天çåè¦æµè¯(使ç¨ä¸æç¹ãç®ãæ¥æãé©æ)åå·²ç»è¯å®å®å
¨ä¸ä¼æä¹±ç ææ¯æäºååæ"å£"ã
ä¾åï¼è¯è
è¾å
¥è¿å 个åãä¸éå¯å¦å°ãå¦æå®ä»¬è½æ£ç¡®è¿å
¥MySQLå被读åºæ¥ï¼é£å°±æ¯ä¸æ没é®é¢äºï¼å¦æ读åºæ¥ååæãå£ãåé£å°±æ¯é©å½è¿æªæååå¿ä»éåªå...orz
å½ç¶æä¹é¡ºä¾¿éªè¯äºflex2 - amfphp - php - MySQLæ¥åä¼ resultsetä¹ä¸åä¼æä¸æä¹±ç é®é¢ï¼å¯ä»¥å®å¿ä½¿ç¨å°ã
上一篇: 微信小程序分享页面后跳转回首页
下一篇: PHP工具类