MySQL操作执行成功,但没有返回值?

Anew_G 2012-07-26 07:03:45
在MySQL console中执行:


mysql>update `1001` set finish=0 where sid=94664;
Query OK,1 row affected (0.07 sec)
Rows matched:1 changed:1 warnings:0



php中的语句:



$tid="`".$_COOKIE['uid']."`";
$which="finish=1";
$where="sid=".$sid;
$db=new Mysql("localhost","root","","members_check","","UTF8");
$db->connect();
$result=$db->update($tid,$which,$where);
echo $result;
//if($result){echo 0;}else{echo 1;}



js那里返回来的就是空,什么都没有。用下面那个if语句返回不了0。但是数据库里全部操作成功。

附上封装的函数:



public function query($sql) {
if ($sql == "") {
echo "SQL语句为空";
}
$this->sql = $sql;
$result = mysql_query($this->sql, $this->conn) or die('faill'.mysql_error());
$this->result = $result;
return $this->result;
}

public function update($table, $mod_content, $condition, $url = '') {
$result=$this->query("UPDATE $table SET $mod_content WHERE $condition");
return $result;
}


...全文
1058 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
Anew_G 2012-07-27
  • 打赏
  • 举报
回复
这次乌龙摆大了。。。。
Anew_G 2012-07-27
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]

$result=$db->update($tid,$which,$where);
var_dump($result);
显示 null

显然LZ使用的代码与他贴出的代码是不一样的
继续讨论是无意义的
[/Quote]

仔细检查了下,找到问题了。./check.php里include的数据库类是我在编辑器里修改的数据库类的副本。我更改的都是最原先的那个数据库类。那里的query语句少了return。多谢楼上各位
xuzuning 2012-07-27
  • 打赏
  • 举报
回复
$result=$db->update($tid,$which,$where);
var_dump($result);
显示 null

显然LZ使用的代码与他贴出的代码是不一样的
继续讨论是无意义的
改一下昵称 2012-07-27
  • 打赏
  • 举报
回复
真是奇怪! 贴一下你的PHP版本,运行平台的信息吧
码无边 2012-07-27
  • 打赏
  • 举报
回复
打印sql UPDATE $table SET $mod_content WHERE $condition
看是不是没有条件没过来!
Anew_G 2012-07-27
  • 打赏
  • 举报
回复
实在不行我用mysql_affected_rows()代替好了,mysql_affected_rows()返回是正常的
Anew_G 2012-07-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

public function update($table, $mod_content, $condition, $url = '') {
$result=$this->query("UPDATE $table SET $mod_content WHERE $condition");
var_dump($result);
return $result;
……
[/Quote]

同样是null
一起混吧 2012-07-26
  • 打赏
  • 举报
回复
public function update($table, $mod_content, $condition, $url = '') {
$result=$this->query("UPDATE $table SET $mod_content WHERE $condition");
var_dump($result);
return $result;
}

这里呢? 是什么结果?
Anew_G 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

$result=$db->update($tid,$which,$where);
var_dump($result);

单独执行php文件,贴出结果。
[/Quote]

一样,显示null,数据库操作成功。



<?php

include_once './check.php';

$cid=77777778;
$sid=94664;
$tid=1001;
$tid="`".$tid."`";
$which="finish=1";
$where="sid="."$sid"." and cid="."$cid";
$db=new Mysql("localhost","root","","members_check","","UTF8");
$db->connect();
$result=$db->update($tid,$which,$where);
var_dump($result);


?>

一起混吧 2012-07-26
  • 打赏
  • 举报
回复
$result=$db->update($tid,$which,$where);
var_dump($result);

单独执行php文件,贴出结果。



改一下昵称 2012-07-26
  • 打赏
  • 举报
回复
引用自手册:
mysql_query() 仅对 SELECT,SHOW,EXPLAIN 或 DESCRIBE 语句返回一个资源标识符,如果查询执行不正确则返回 FALSE。对于其它类型的 SQL 语句, mysql_query() 在执行成功时返回 TRUE,出错时返回 FALSE
而你的代码我又没看出什么问题,我无解了
Anew_G 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

这是个奇怪的问题,以至于我很怀疑你描述的
在代码后面加上一句 var_dump($result, mysql_error()); 贴出结果
[/Quote]



<pre class='xdebug-var-dump' dir='ltr'><font color='#3465a4'>null</font></pre>

<pre class='xdebug-var-dump' dir='ltr'>
<small>string</small>
<font color='#cc0000'></font>
<i>(length=0)</i>
</pre>




这段代码是用于处理post请求的,所以我直接用alert(data)显示出来了。以上
改一下昵称 2012-07-26
  • 打赏
  • 举报
回复
这是个奇怪的问题,以至于我很怀疑你描述的
在代码后面加上一句 var_dump($result, mysql_error()); 贴出结果
Anew_G 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

echo 用于输出字符串,而你的 Mysql::update()返回值是布尔值,因此 echo true;当然得不到任何东西。
[/Quote]

我用if($result){echo 0;}else{echo 1;}的话,不返回0
改一下昵称 2012-07-26
  • 打赏
  • 举报
回复
echo 用于输出字符串,而你的 Mysql::update()返回值是布尔值,因此 echo true;当然得不到任何东西。
一起混吧 2012-07-26
  • 打赏
  • 举报
回复
不知道在说什么

21,882

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧