Here is the class, I wrote. There are no errors when I execute the findbyAdNetID method. However, the method is not fetching any data. The same code works if I put it outside a class and remove instance variables $this everywhere. Any help would be appreciated. Thanks.

我写道,这是课程。执行findbyAdNetID方法时没有错误。但是,该方法不提取任何数据。如果我将它放在一个类之外并且在任何地方删除实例变量$ this,则相同的代码可以工作任何帮助,将不胜感激。谢谢。

<?php

class adscraper_mysqli
{
private $id;
private $result;
private $rows;
private $_mysqli;
private $statement;
private $query ="SELECT * FROM scrapelist_master WHERE ad_network_id=?";

public function __construct($host = NULL, $username = NULL, $password = NULL, $db = NULL)
{
    $this->host = $host;
    $this->username = $username;
    $this->password = $password;
    $this->db = $db;
    $this->connect();
}

/**
 * A method to connect to the database
 *
 */
public function connect()
{

    $this->_mysqli = new mysqli ($this->host, $this->username, $this->password, $this->db)
    or die('There was a problem connecting to the database');
}

/**
 * A method to create prepared statements
 *
 */
public function prepare()
{
    $this->statement = $this->_mysqli->prepare($this->query);
}
/* Method to query using prepared statement */
public function findbyAdNetID($id){
    if (!$this->statement) {
        $this->prepare();
    }
    $this->statement->bind_param("i", $this->id);
    $this->statement->execute();

    $this->result = $this->statement->get_result();

    $this->rows = $this->result->fetch_all(MYSQLI_ASSOC);
    return $this->rows;

}

} // END class
 ?>

`

1 个解决方案

#1


All the code is written in the right way. The only problem, why you've got nothing is, that in findbyAdNetID($id) method is row:

所有代码都以正确的方式编写。唯一的问题,为什么你什么都没有,在findbyAdNetID($ id)方法是行:

    $this->statement->bind_param("i", $this->id);

But you didn't set $this->id. So you have to use only $id instead of, like

但你没有设置$ this-> id。所以你必须只使用$ id代替

    $this->statement->bind_param("i", $id);

or set it at the beginning

或者在开头设置它

    $this->id = id;

更多相关文章

  1. PHP用空格分割文本为数组的方法
  2. 几个有用的php字符串过滤,转换函数代码
  3. 高效的敏感词过滤方法(PHP)
  4. php static静态变量及方法详解
  5. laravel 4路由::控制器()方法返回NotFoundHttpException。
  6. PHP上传文件 Error 6解决方法
  7. 基于PHP的UUID/GUID/uniqid替换方法及其可靠性论述
  8. 有一种防弹的方法可以检测php字符串中的base64编码吗?
  9. PHP实现接口方法时出现致命错误

随机推荐

  1. activity的android:name类名的简写方式
  2. 从头到尾给你讲明白Android(安卓)View实
  3. Android解析ClassLoader(二)Android中的Cla
  4. 【Android 开发】: Android 消息处理机制
  5. Android的NDK开发步骤
  6. Android音乐播放器汇总贴
  7. Android 去掉 Launcher3 里面默认的Googl
  8. android:id="@+id/android:empty属性的用
  9. android 电池(三):android电池系统
  10. Android xmlns 的作用及其自定义