Estoy tratando de contar el número de filas en un resultado, y sigo recibiendo el error anterior. He revisado el manual y estoy usando mysqli_result :: num_rows() como debería ser (estoy usando el estilo orientado a objetos). Tengo tres clases trabajando aquí.Llamada a la función no definida mysqli_result :: num_rows()
Clase (Conexión):
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;
}
}
Clase (manijas Resultado): función
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();
}
}
Clase:
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;
}
}
La página de prueba que estoy usando para llamar a todo esto es (la instrucción include es solo la función __autoload() que funciona bien):
$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;
}
Nota: originalmente no tenían el: –
Nota: originalmente no tenía el 'código' $ this-> store_result (); 'código' en la función, simplemente lo agregó después de algunas investigaciones y pensó que podría ser útil. –
Retire los soportes. $ this -> _ result-> num_rows(); a $ this -> _ result-> num_rows; Me funcionó –