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需要用‘’包裹