0
I’m new to PHP PDO, I’m using MVC and I couldn’t do the line count on database using $obj->rowCount();
Just follow my code
php model.:
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 saw I’m wearing count()
to make the count because I could not do using rowCount();
for lack of logic :/
Counting lines reached PDO
– rray
Look at the function, for example
$sql = $obj->read(aqui a query)
I can’t do this$sql->rowCount()
'-'– Guilherme Alves