求问以下方法为何不能得到返回值

PHP中文网
Release: 2023-02-28 13:24:01
Original
944 people have browsed it

  求问以下方法为何不能得到返回值?

由解,以下疑问!

public static function query($sql, $unbuffered = false) {
    $ret = self::$db->query($sql, $unbuffered);//该句成功时$ret为1  注::self::$db->query为mysql_query
    if ($unbuffered===true) {
      $cmd = trim(strtoupper(substr($sql, 0, strpos($sql, ' '))));
      if ($cmd === 'SELECT') { } 
      elseif ($cmd === 'UPDATE' || $cmd === 'DELETE') {
          $ret = self::$db->affected_rows();
      } 
      elseif ($cmd === 'INSERT') {
          $ret = self::$db->insert_id();//该处运行时证明执行了,返回的是int类型id号
      }
   }
   return $ret;//最终返回不是int类型id号
}
Copy after login

                           


------解决方案--------------------
那你得到的是什么?
------解决方案--------------------
无论是否有后续操作,至少会返回 $ret = self::$db->query($sql, $unbuffered); 的值
既然是:该句成功时$ret为1,而你说返回为空,显然是查询失败了
------解决方案--------------------
由 public function query($sql, $unbuffered = false) { ... 可知
要么 query 返回资源,要么 query 返回逻辑值
------解决方案--------------------
你执行的sql是什么?执行query时,$unbuffered是什么?
------解决方案--------------------
你用elseif  如果某个条件断了下面的程序就不会再走

 以上就是求问以下方法为何不能得到返回值的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!