duanchun2349 2013-07-07 22:32
浏览 429
已采纳

函数getResult调用

I'm working transferring my functions from MySQL to MySQLi standards.

This is my old function for getresult

  function getResult($sql) {
            $result = mysql_query($sql, $this->conn);
            if ($result) {
                return $result;
            } else {
                die("SQL Retrieve Error: " . mysql_error());
            }
        }

However, I have been following the W3schools on the mysqli_query function. Here's where I'm presently at.

 function getResult($connection){
        $result = mysqli_query($connection->conn);
        if ($result) {
            return $result;
        } else {
            die("SQL Retrieve Error: " . mysqli_error());
        }
    }

Now, the examples on W3schools are just a bit different from how I want to use mysqli_query. I'm trying to make it be directed at my DB, not some input or constants as per examples on W3S.

Notice: Trying to get property of non-object in C:\xampp\htdocs\cad\func.php on line 92

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\cad\func.php on line 92

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\cad\func.php on line 96
SQL Retrieve Error:

Thank you

  • 写回答

2条回答 默认 最新

  • douyamitong57935 2013-07-07 22:40
    关注

    Your version won't work for a number of reasons, not the least of which is that you haven't included the query you want to send. Assuming $this->conn is set up properly somehow, try this:

     function getResult($sql) {
            $result = mysqli_query($this->conn, $sql);  //Note parameters reversed here.
            if ($result) {
                return $result;
            } else {
                die("SQL Retrieve Error: " . mysql_error());
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度