我在application/config/database.php加了:
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
我用的就是UTF8.
模型:class books_model extends Model
{
function __construct(){
parent::Model();
}
/*
function get_books($num, $offset) {
$query = $this->db->get('christian_books', $num, $offset);
return $query;
}*/
function get_pro_books()
{
//加上下面这句就不会有乱码了,
$this->db->query('SET NAMES utf8');
$query=$this->db->query('SELECT * FROM book');
if ($query->num_rows() > 0)
{
$rows= $query->result();
}
return $rows;
}
}
?>
控制器:
class Books extends Controller {
function __construct() {
parent::Controller();
$this->load->helper('url');
$this->load->database();
}
function index() {
//load the model and get results
$this->load->model('books_model');
$data['results'] = $this->books_model->get_pro_books();
$data['hi']="这里的汉字没有错!";
// load the view
$this->load->view('books_view', $data);
}
}
lNew Page | xHTML1.0 Transitional?>
视图:
<html>
<head>
</head>
<body>
<?php foreach($results as $row):?>
<?=$row->author?>
<?php endforeach;?>
<?=$hi?>
</body>
</html>
出来的结果是???????????????????这里的汉字没有错!
[ 本帖最后由 默生 于 2008-6-13 10:03 编辑 ] |