主機 Ubutu 14.04.06 + PHP5.5
下 pear list 指令

先升級 pear
pear install PEAR-1.10.10
再安裝 DB套件
pear install DB

引入 DB
require “DB.php”;
連接mysql資料庫
$dsn = "mysql://{$mysql_user}:{$mysql_pass}@{$mysql_host}/{$db_name}";
$dbCon = DB::connect($dsn);
$sqlstr=" select * from gov ";
$sth = $dbCon->query($sqlstr);
三種取值方法
Method-1
$row = $sth->fetchRow(DB_FETCHMODE_ASSOC);
print "first".$row[gov_code]."-".$row[login_pass]."
";
Method-2
$row1 = $sth->fetchRow(DB_FETCHMODE_OBJECT);
print "second".$row1->gov_code."-".$row1->login_pass."
";
Method-3
$row2 = $sth->fetchRow();
print "third".show_array($row2)."
";
設定中文編碼UTF8
$dbCon->query('SET NAMES utf8');