第一种:
$conn[‘host‘] = ‘127.0.0.1‘;
$conn[‘username‘] = ‘56_‘ . $tenant[‘tenant‘];
$conn[‘password‘] = $tenant[‘password‘];
$conn[‘dbname‘] = ‘56_‘ . $tenant[‘tenant‘];
$conn[‘charset‘] = ‘utf8‘;
$this->_db = Zend_Db::factory(‘PDO_MYSQL‘, $conn);
Zend_Db_Table::setDefaultAdapter($this->_db);
//为抽象类Zend_Db_Table对象设定默认的adapter
Zend_Registry::set(‘db‘, $this->_db);
第二种:
<?php $dbAdapter=Zend_Db::factory($config->general->db->adapter,
$config->general->db->toArray());
$dbAdapter->query("SET NAMES utf8"); ?>
第三种:普通php页面连接时置为uft8编码
<?php
//数据库连接
$conn = @mysql_connect("localhost","root","");
if (!$conn){
die("连接数据库失败:" . mysql_error());
}
mysql_select_db("testdb", $conn);
//字符编码转换_读数据库
mysql_query("set character set ‘utf8‘");
//字符编码转换_写数据库
mysql_query("set names ‘utf8‘");
?>