I'm new with PHP PDO , I'm using MVC and could not count the lines in the database using% / p>
Follow my code
model.php :
public function read($table, $fields, $where = null, $fetchMode = PDO::FETCH_ASSOC) {
$where = isset($where) ? "WHERE {$where}" : "";
$sql = $this->db->query("SELECT {$fields} FROM {$table} {$where} ");
return $sql->fetchAll($fetchMode);
}
login_model.php
public function login() {
$id = 1;
$sql = $this->read('users', 'email', "id={$id}");
print_r($sql);
if (count($sql) >= 1) {
echo 'é maior';
} else {
echo 'é menor';
}
}
As you can see, I am using $obj->rowCount();
to do the count, because I could not do it using count()
because of lack of logic: /