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

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

require_once 'Zend/Db.php';
require_once 'Zend/Db/Table.php';
$params = array ('host'     => 'localhost',
                 'username' => 'root',
                 'password' => 'yourpassword',
                 'dbname'   => 'yourdbname');
$db = Zend_Db::factory('PDO_MYSQL', $params);
$db->query('set names utf8');
Zend_Db_Table::setDefaultAdapter($db);
class ContentTable extends Zend_Db_Table {
protected $_name = 'jos_content';
}
$table = new ContentTable();
$rowset = $table->fetchAll(null, 'id ASC', 10, 0);
$title = '';
foreach ($rowset as $row) {  
   $title.=$row->title;
}

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

+1 21

留下你的看法: