php数据库插入数据失败
本帖最后由 baidu_21003671 于 2014-09-20 20:19:25 编辑 class mysql{
private $host;
private $name;
private $pass;
private $table;
private $ut;
function __construct($host,$name,$pass,$table,$ut){
$this->name=$name;
$this->host=$host;
$this->pass=$pass;
$this->table=$table;
$this->ut=$ut;
}
function connect(){
if ($link=mysql_connect($this->host,$this->name,$this->pass)or die($this->error())){
/*echo "成功";*/
}//链接数据库
if(mysql_select_db($this->table,$link)or die("没该数据库".$this->table));
/*echo "成功";*/
mysql_query("SET NAMES'$this->ut'");
}
function query($v){
return mysql_query($v);
}
function error(){
return mysql_error();
}
function close(){
return mysql_close();
}
/*---------------------*/
function fn_insert($table,$name,$value){
if ($this->query("INSERT INTO $table ($name) VALUES ($value)")){
echo "成功";
}else {
echo "失败";
}
}
}
$a=new mysql('127.0.0.1','root','','','GBK');
$a->connect();
$a->fn_insert('test','id,user,tittle', '24,php800,测试');
$a->close()
语法没错误 链接数据库也正常 为什么就是插入数据就是失败呢
------解决思路----------------------$a->fn_insert('test','id,user,tittle', "'24','php800','测试'");
------解决思路----------------------$a=new mysql('127.0.0.1','root','123456','test','GBK');
$a->connect();
$a->fn_insert('test','id,user,title', "24,'php800','测试'");
$a->close();
检查检查先
1.没有指定数据库
2.title应该拼写错误
3.varchar需要用‘’包裹