I have just changed my database connection. I am not used to the PDO class or OOP yet. Anyway, I connect to the db like this:
$dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME;
try
{
$this->db = new PDO($dsn, DB_USER, DB_PASS);
}
catch ( Exception $e )
{
die ( $e->getMessage() );
}
I am trying to get number of rows from this query:
$ip = $this->ip();
$sql = "SELECT `id` FROM `login_failed`
WHERE `ip` = :ip AND `time` BETWEEN NOW( ) - INTERVAL 120 MINUTE AND NOW( )
LIMIT 3";
try
{
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':ip', $ip, PDO::PARAM_STR);
$result = $stmt->execute(); // $result = true
$n = $stmt->num_rows ; // n = NULL?
$stmt->closeCursor();
}
catch (Exception $e)
{
die ($e->getMessage() );
}
In phpmyadmin
I get a result so my query is correct, but $n
is NULL
for some reason.. How do I get number of rows with PDO