So when I get to Classe
Plans below
<?php
namespace CONTROLES;
class Planos {
private $conexao;
public function __construct ($_conexao) {
$this->conexao = $_conexao;
}
public function pesquisaPlano($idPlano) {
$plano = null;
$string = "SELECT
idPlano,
nome,
descricao
FROM planos
WHERE idPlano = ".$idPlano;
$registros = $this->conexao->query($string);
$quantasLinhas = $registros->num_rows;
if ($quantasLinhas > 0) {
list ($idPlano, $nome, $descricao) = $registros->fetch_row();
$plano = new Planos($nome, $descricao);
$plano->setIdPlano($idPlano);
}
return $plano;
}
public function pesquisaPlanos($where = NULL) {
$planos = null;
$string = "SELECT idPlano, nome, descricao FROM planos ".$where;
print "<pre>";
print_r ($this->conexao);
print "</pre>";
$registros = $this->conexao->query($string);
$quantasLinhas = $registros->num_rows;
if ($quantasLinhas > 0) {
while (list ($idPlano, $nome, $descricao) = $registros->fetch_row()) {
$plano = new Planos($nome, $descricao);
$plano->setIdPlano($idPlano);
$planos[] = $plano;
}
}
return $planos;
}
}
?>
When you run the method
public function pesquisaPlanos($where = NULL) {
$planos = null;
$string = "SELECT idPlano, nome, descricao FROM planos ".$where;
print "<pre>";
print_r ($this->conexao);
print "</pre>";
$registros = $this->conexao->query($string);
$quantasLinhas = $registros->num_rows;
if ($quantasLinhas > 0) {
while (list ($idPlano, $nome, $descricao) = $registros->fetch_row()) {
$plano = new Planos($nome, $descricao);
$plano->setIdPlano($idPlano);
$planos[] = $plano;
}
}
return $planos;
}
I get the print_r ()
mysqli Object
(
[affected_rows] => 0
[client_info] => mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $
[client_version] => 50012
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[error_list] => Array
(
)
[field_count] => 0
[host_info] => localhost via TCP/IP
[info] =>
[insert_id] => 0
[server_info] => 5.7.20-log
[server_version] => 50720
[stat] => Uptime: 64318 Threads: 1 Questions: 105 Slow queries: 0 Opens: 114 Flush tables: 1 Open tables: 107 Queries per second avg: 0.001
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 32
[warning_count] => 0
)
Which leads me to believe that the connection object was created.
Testing query on MySQL returns values.
But when I do in php
if ($quantasLinhas > 0) {
Returns 0 rows. That is, none.
Where is the error?