您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

求问我自己写的这个DB类,哪里错了,插不进数据

2024/6/24 7:41:27发布29次查看
hostname = $hostname; $this->username = $username; $this->password = $password; $this->select_db = $select_db; $this->con = mysql_connect($this->hostname,$this->username,$this->password); if(!$this->con){ $this->error = die('could not connect:'.mysql_error); } else{ mysql_select_db($this->select_db,$this->con); } } } public function __destruct(){//退出时结束连接 mysql_close($this->con); } public function insert($table,$body){//插入table中的一个数组 $line1 = implode(',',$body); $line2 = implode(',',array_keys($body)); echo $sql = insert into $table ($line2) values ($line1); $result = mysql_query($sql,$this->con); if(!$result){ echo $this->error; echo '111'; } } public function update($table,$body){ } public function read($table,$keyword){ } public function delete($table,$keyword){ } public function getlasterror(){//返回最后一条错误信息 return $this->error; } }?>
主页调用的是 '`aa`', 'bb'=>'`dd`' ); $db->insert('1234',$line1);?>
echo $sql语句是insert into 1234 (aa,bb) values (`aa`,`dd`)
回复讨论(解决方案) 用mysql_error查询$this->con,没有返回错误信息。。。。我现在很抓狂- -求人解答啊。。。。
require('db.class.php');
    $db = new db('localhost','root','','dbtest');
    $line1 = array(
            'aa'=> 'aa',
            'bb'=> 'dd'
    );
    $db->insert('1234',$line1);
你的$line1数组写反了。
而且insert 语句还有一种格式:insert into tb_member set username = test, type = 1, lastlogindt = now()。跟update样式差不多。
你也可以看看人家写的数据库类,我感觉挺好的:http://www.cnblogs.com/hooray/archive/2012/07/21/2603017.html
你的$line1数组写反了。
而且insert 语句还有一种格式:insert into tb_member set username = test, type = 1, lastlogindt = now()。跟update样式差不多。
你也可以看看人家写的数据库类,我感觉挺好的:http://www.cnblogs.com/hooray/archive/201…… 其实没写反- -三楼指出来了。。。都是些小符号的问题。。。。。
require('db.class.php');
    $db = new db('localhost','root','','dbtest');
    $line1 = array(
            'aa'=> 'aa',
            'bb'=> 'dd'
    );
    $db->insert('1234',$li…… 唉- -总是些奇奇怪怪的小错误。。。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product