+ -
当前位置:首页 → 问答吧 → 大家来看看,我怎么往mysql里加不了信息啊?

大家来看看,我怎么往mysql里加不了信息啊?

时间:2010-01-31

来源:互联网

代码如下:
<?php
/*
 * Created on 2010-1-27
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 class mysql{
  private $host;
  private $name;
  private $pass;
  private $table;
function __construct($host,$name,$pass,$table){
 $this->host=$host;
 $this->name=$name;
 $this->pass=$pass;
 $this->table=$table;
 $this->connect();
}
function connect(){
 $link=mysql_connect($this->host,$this->name,$this->pass)or die($this->error());
    mysql_select_db($this->table,$link) or die('没有数据库'.$this->table);
 }
 function query($sql,$type = '') {
     if(!($query = mysql_query($sql))) $this->show('Say:', $sql);
     return $query;
 }
   function show($message = '', $sql = '') {
  if(!$sql) echo $message;
  else echo $message.'<br>'.$sql;
 }
 function error(){
  return mysql_error();
 }
 //==============
 function fn_insert($table,$name,$value){
  $this->query("insert into $table($name) value($value)");
 }
}

$db = new mysql('localhost','root','3889159','test');
$db->fn_insert('test','id,title,dates',"'','我插入的信息',now()");
?>
也没有报错 但就是插入不了数据库 这到底是怎么回事啊 Eclipse显示为:Say:
insert into test(id,title,dates) value('','我插入的信息',now())
是不是我的sql语句写的有问题啊?请教大家了

作者: jtchgong   发布时间: 2010-01-31


fn_insert函数中SQL出现错误
value少了个s

作者: vidon   发布时间: 2010-02-01

funciton fn_insert($table,$name,$value)
$this->query("insert into $table($name) values ($value)");

作者: yuejide   发布时间: 2010-02-01

我改了啊 可还是不行 啊 还是说Say:
insert into test(id,title,dates) values('','我插入的信息',now())

作者: jtchgong   发布时间: 2010-02-01

哦  可以了  谢谢楼上的朋友们哈 确实是我的sql语句写错了,下次注意了 呵呵!

作者: jtchgong   发布时间: 2010-02-01

还有就是我把id的值 要写上数字 才能成功 id是自增的 不写的话也可以传成功 ,要是不写数字就初步成功,为什么?

作者: jtchgong   发布时间: 2010-02-01

视频教程上 也没写id的值 就可以传成功 奇怪

作者: jtchgong   发布时间: 2010-02-01

相关阅读 更多

热门下载

更多