有关于Zend_Db_Table
2012-1-30 11:32 Monday  

分类: PHP 评论(62) 浏览(30118)

01require_once 'Zend/Db.php';
02require_once 'Zend/Db/Table.php';
03$params = array ('host'     => 'localhost',
04                 'username' => 'root',
05                 'password' => 'yourpassword',
06                 'dbname'   => 'yourdbname');
07$db = Zend_Db::factory('PDO_MYSQL', $params);
08$db->query('set names utf8');
09Zend_Db_Table::setDefaultAdapter($db);
10class ContentTable extends Zend_Db_Table {
11protected $_name = 'jos_content';
12}
13$table = new ContentTable();
14$rowset = $table->fetchAll(null, 'id ASC', 10, 0);
15$title = '';
16foreach ($rowset as $row) { 
17   $title.=$row->title;
18}

注意这一行:$db->query('set names utf8');
因为数据库的默认字符集是是utf8 ,所以这一行是必须的,否则你读出来的中文就成了乱码了。

+1 28

留下你的看法: