mysql版本过高的话就不支持这种格式?该怎么处理

WBOY
Release: 2016-06-13 13:23:43
Original
843 people have browsed it

mysql版本过高的话就不支持这种格式?
mysql版本过高的话就不支持 insert into $tb(表) set $var(字段=字段值) 这种格式?
父类:
class mysql{
  public $host; //主机
  public $db; //数据库
  public $user; //用户名
  public $pass; //密码
  public $set; //编码
function __construct($m,$a,$b,$n,$c){
//function fun($m,$a,$b,$n,$c){
$this->host=$m;
$this->user=$a;
$this->pass=$b;
$this->db=$n;
$this->set=$c;
$this->conn();
}
//链接数据库
function conn(){
mysql_connect($this->host,$this->user,$this->pass)or die($this->log_sn());
mysql_select_db($this->db)or die($this->log_sn("数据库链接错误!"));
mysql_query("setnames.'".$this->set."'");
}
//执行sql语句
function query($n){
return mysql_query($n);
}
function f($q,$f=1){
if($f){
return mysql_fetch_array($q);
}else{
return mysql_fetch_row($q);
}
}
//获取id
function id_in(){
return mysql_insert_id();
}
//建立数据库日志
  function log_sn($son=""){
  $son="##".date("Y-m-d H:i:s")."##".mysql_error().$son."\r\n";
  $fp=fopen(date(ymd).".txt", a);
  fwrite($fp,$son);
  fclose($fp);
  }
}

子类:
class act extends mysql{
function insert($tb,$var,$state=0){
$sql="insert into".$tb."set".$var;
if($state){
echo $sql;
}else{
mysql_query($sql);
//return $this->id_in();
}
}

页面:
include('mysql.class.php');
include('act.class.php');
$insert=new act("localhost","root","","news","gbk");
$insert->insert("news","id=null,title='臭不要脸',author='张',tid='333',pic='a.jpg',sort='2',hit='0',adtime=130229197,uptime=1302292988,del='N'");


页面执行之后,数据库没有插入成功,也不报错,但是打印出来的sql语句在数据库里是可以用的,是mysql版本问题吗?还是我的代码有问题?

------解决方案--------------------
传入参数 "news","id=null,title='臭不要脸',author='张',tid='333',pic='a.jpg',sort='2',hit='0',adtime=130229197,uptime=1302292988,del='N'"

构造 sql 串
$sql="insert into".$tb."set".$var;
得到的应该是:
insert intonewssetid=null,title= ......
都粘在一起了,能不错吗?

另外你的 id 是自增字段就不要写了

------解决方案--------------------
插入表的操作:
INSERT INTO TABLE (field) VALUES(field_value);
修改表的操作:
UPDATE TABLE SET field=new_value WHERE field=field_value;
------解决方案--------------------
"但是打印出来的sql语句在数据库里是可以用的" 
 
打印出来的什么样? 

据手册, insert ... set... 最新的5.6都支持,没有问题
所以还是得查你的程序

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template