01 | require_once 'Zend/Db.php' ; |
02 | require_once 'Zend/Db/Table.php' ; |
03 | $params = array ( 'host' => 'localhost' , |
05 | 'password' => 'yourpassword' , |
06 | 'dbname' => 'yourdbname' ); |
07 | $db = Zend_Db::factory( 'PDO_MYSQL' , $params ); |
08 | $db ->query( 'set names utf8' ); |
09 | Zend_Db_Table::setDefaultAdapter( $db ); |
10 | class ContentTable extends Zend_Db_Table { |
11 | protected $_name = 'jos_content' ; |
13 | $table = new ContentTable(); |
14 | $rowset = $table ->fetchAll(null, 'id ASC' , 10, 0); |
16 | foreach ( $rowset as $row ) { |
注意这一行:$db->query('set names utf8');
因为数据库的默认字符集是是utf8 ,所以这一行是必须的,否则你读出来的中文就成了乱码了。
留下你的看法: