看板 PHP 關於我們 聯絡資訊
※ 引述《buganini (霸格尼尼)》之銘言: : ※ 引述《kingmin (高手)》之銘言: : : 這是我的phpMyAdmin畫面 : : http://img543.imageshack.us/img543/5405/20101009120719.jpg
: : 這是我的資料表 : : http://img269.imageshack.us/img269/3784/20101009120743.jpg
: : 這是我的資料表裡的結構 : : http://img704.imageshack.us/img704/3241/20101009120809.jpg
: : 我PHP已全部改成utf8並設定無BOM : : PHP裡面也有加入了mysql_query("SET NAMES 'utf8'"); : : 請問現在PHP從 因該是BIG5的 MYSQL裡取出的資料會變成亂碼 : 應 : 那怎麼charset/collation全都是utf-8 ? : : 不過我測試 : : INSERT INTO `search` (`ip` ,`name` ,`time` ,`code` )VALUES ('127.0.0.1', : : 'Guest' , 1286598087 , '中文測是' ); : 試 : : 從phpMyAdmin裡看到的是中文 : : 所以顯示出網頁也是中文沒問題 : : 請問如果我想把資料庫改用UTF8 : (A) : 如果你用phpmyadmin看資料庫內容都正確的話 : 沒意外的話應該本來就是囉 : : 並且用CurlRequest從外部更新資料庫的資料 : : 可是資料庫裡中文都不見了 變成是空的 : : 如果PHP裡面改成mysql_query("SET NAMES 'big5'"); : : 在從外部更新資料庫的資料 在從phpMyAdmin裡看到的就是中文 : 這樣看起來是資料庫存UTF-8, 網頁用Big5 : : 不過PHP上看到的就變成亂碼了??? : : 請問如何設定才能存入資料是BIG5 取出資料是UTF8 : 有這個必要嗎? 為什麼還要用Big5 ? : 除非你的資料庫要跟別人的程式共用 : 如果是這樣的話那之後再說 : 可是怎麼跟(A)那邊的說法不同?? 這是連結資料庫 function DB($v_host, $v_database, $v_user, $v_password){ mysql_connect($v_host,$v_user,$v_password) or die("無法連結服務器"); mysql_query("SET NAMES 'utf8'"); if(!mysql_select_db($v_database)){mysql_query("CREATE DATABASE `$v_database`");} mysql_select_db($v_database) or die("無法打開打開數據庫"); } 這CURL應該跟網路上找的道程式碼的差不多 class CurlRequest{ private $ch; public function init($params) { $this->ch = curl_init(); $proxy=trim($params['proxy']); $user_agent1 = array('Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-TW; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8','Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)','Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322)','Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)'); $rand=rand(0,4); $user_agent = $user_agent1[$rand]; $header = array( "Accept: */*", "Accept-Language: ru-ru,ru;q=0.7,en-us;q=0.5,en;q=0.3", "Accept-Charset: UTF-8,windows-1251;q=0.7,*;q=0.7", "Keep-Alive: 300"); if (isset($params['host']) && $params['host']) $header[]="Host: ".$host; if (isset($params['header']) && $params['header']) $header[]=$params['header']; @curl_setopt ( $this -> ch , CURLOPT_RETURNTRANSFER , 1 ); @curl_setopt ( $this -> ch , CURLOPT_VERBOSE , 1 ); @curl_setopt ( $this -> ch , CURLOPT_HEADER , 1 ); if ($params['method'] == "HEAD") @curl_setopt($this -> ch,CURLOPT_NOBODY,1); @curl_setopt ( $this -> ch, CURLOPT_FOLLOWLOCATION, $params['location']); @curl_setopt ( $this -> ch , CURLOPT_HTTPHEADER, $header ); if ($params['referer']) @curl_setopt ($this -> ch , CURLOPT_REFERER, $params['referer'] ); @curl_setopt ( $this -> ch , CURLOPT_USERAGENT, $user_agent); if ($params['cookie']) @curl_setopt ($this -> ch , CURLOPT_COOKIE, $params['cookie']); if ( $params['method'] == "POST" ){ curl_setopt( $this -> ch, CURLOPT_POST, true ); curl_setopt( $this -> ch, CURLOPT_POSTFIELDS, $params['post_fields'] ); } if (!empty($proxy)){ curl_setopt( $this -> ch, CURLOPT_PROXY, $proxy);$proxy1=$proxy;} @curl_setopt ( $this -> ch, CURLOPT_URL, $params['url']); @curl_setopt ( $this -> ch , CURLOPT_SSL_VERIFYPEER, 0 ); @curl_setopt ( $this -> ch , CURLOPT_SSL_VERIFYHOST, 0 ); if (isset($params['login']) & isset($params['password'])) @curl_setopt($this -> ch , CURLOPT_USERPWD,$params['login'].':'.$params['password']); @curl_setopt ( $this -> ch , CURLOPT_TIMEOUT, $params['timeout']); } public function exec() { global $debug1,$nn,$proxy,$proxy1; $response = curl_exec($this->ch); $error = curl_error($this->ch); $result = array( 'header' => '', 'body' => '', 'curl_error' => '', 'http_code' => '', 'last_url' => ''); if ( $error != "" ){ $result['curl_error'] = $error; return $result; } $header_size = curl_getinfo($this->ch,CURLINFO_HEADER_SIZE); $result['header'] = substr($response, 0, $header_size); $result['body'] = substr( $response, $header_size ); $result['http_code'] = curl_getinfo($this -> ch,CURLINFO_HTTP_CODE); $result['last_url'] = curl_getinfo($this -> ch,CURLINFO_EFFECTIVE_URL); if($debug1){ echo $result['http_code']."<br>".$result['header']."<br><br>".$result['body']."<br>";} if(!empty($proxy1)){ if($result['http_code'] <> "200" and $result['http_code'] <> "302"){updataproxy();}} return $result; } } mysql_query("SET NAMES 'utf8'"); 我也用了這四種//UTF-8 utf8 big5 Big5 還是不行???? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.115.19.192