Sonuçtaki satır sayısını saymaya çalışıyorum ve yukarıda verilen hatayı alıyorum. Elkitabını kontrol ettim ve olması gerektiği gibi mysqli_result :: num_rows() kullanıyorum (nesne tabanlı stil kullanıyorum.) Burada üç sınıf çalışıyorum.Tanımlanmamış işlev çağrısı mysqli_result :: num_rows()
Sınıf (Bağlantı):
class utils_MysqlImprovedConnection {
protected $_connection;
public function __construct($host, $user, $pwd, $db)
{
$this->_connection = @new mysqli($host, $user, $pwd, $db);
if(mysqli_connect_errno()) {
throw new RuntimeException('Cannot access database:' . mysqli_connect_error());
}
}
public function getResultSet($sql)
{
$results = new utils_MysqlImprovedResult($sql, $this->_connection);
return $results;
}
public function __destruct() {
$this->_connection;
}
}
Sınıf (Sonucu kolları):
class utils_MysqlImprovedResult implements Iterator, Countable {
protected $_key;
protected $_current;
protected $_valid;
protected $_result;
public function __construct($sql, $connection) {
if (!$this->_result = $connection->query($sql)){
throw new RuntimeException($connection->error . '. The actual query submitted was: '. $sql);
}
}
public function rewind()
{
if (!is_null($this->_key)){
$this->_result->data_seek(0);
}
$this->_current = $this->_result->fetch_assoc();
$this->_valid = is_null($this->_current) ? false : true;
}
public function valid()
{
return $this->_valid;
}
public function current()
{
return $this->_current;
}
public function key()
{
return $this->_key;
}
public function next()
{
$this->_current = $this->_result->fetch_assoc();
$this->_valid = is_null($this->_current) ? false : true;
$this->_key++;
}
public function count()
{
$this->_result->store_result();
$this->_result->num_rows();
}
}
Sınıf işlevi:
public function resetPassword($email, $pass){
//check if email exists, update authkey and password, send email
$sql = "SELECT * FROM table WHERE column = '$email'";
$results = $this->_db->getResultSet($sql);
if($results->count() == 1){
// Process
$this->_message = "Success!";
return $this->_message;
} else {
// Not unique
$this->_error = "Try again";
return $this->_error;
}
}
Bütün bu çağırmak için kullanıyorum test sayfası (deyim sadece iyi çalışıyorsa __autoload() işlevini içerir):
$columnvar = '[email protected]';
$pass = 'blah';
require_once 'inc.init.php';
$user = new utils_User();
try{
$string = $user->resetPassword($email, $pass);
echo $string;
}
catch(Exception $e) {
echo $e;
}
not karıştırmak istiyorum: –
not: başlangıçta yoktu başlangıçta 'kod' $ this-> store_result yoktu (); funcitondaki 'code', bazı araştırmalardan sonra ekledi ve yardımcı olabileceğini düşündü. –
Parantezleri çıkarın. $ this -> _ result-> num_rows(); bunu $ -> _ sonuç-> num_rows; Benim için çalıştı –