-1
這是我寫的類。當我執行findbyAdNetID方法時沒有錯誤。但是,該方法不提取任何數據。如果我把它放在一個類的外面並且除去實例變量$ this,那麼相同的代碼就可以工作。任何幫助,將不勝感激。謝謝。mysqli類使用準備好的語句不返回任何數據
<?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
?>
`
設置你用調試器來看看會發生什麼,並且該值由每個返回了什麼電話?我會從這裏開始。 – mins