php資料庫插入資料失敗解決辦法

來源:互聯網
上載者:User
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需要用‘’包裹
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.