mysql_query("SET NAMES '$this->ut'");出现乱码
mysql_query("SET NAMES 'GBK'");不出现乱码
源代码
<?php
class mysql
{
private $host;
private $name;
private $pass;
private $db;
private $ut;
function __construct($host,$name,$pass,$db,$ut)
{
$this->host=$host;
$this->name=$name;
$this->pass=$pass;
$this->db=$db;
$this->connect();
$this->ut=$ut;
}
function connect()
{
$link = mysql_connect($this->host,$this->name,$this->pass) or die($this->error());
mysql_select_db($this->db,$link)or die("没有数据库:".$this->db);
mysql_query("set names '$this->ut'");
}
function query($v)
{
return mysql_query($v);
}
function error()
{
return mysql_error();
}
function fn_insert($table,$name,$value )
{
$this->query("insert into $table($name)value($value)");
}
}
$database = new mysql("localhost","root","","bbs","GBK");
$database->fn_insert
("message","id,user,title,content,lastdate","'','妈妈','标题是','内容是',now()");
?>