PDO görünüşe satır sayısı (mysqli num_rows değişkeni vardır) bir seçme sorgusu döndürülen saymak için hiçbir anlamı vardır.
Bunu yapmanın bir yolu count($results->fetchAll()) kullanarak kısa, var mı?
Kılavuza göre, PDOStatement->rowCount yöntem yoktur; ancak kullanılan (quoting) olmamalıdır:
For most databases,
PDOStatement::rowCount()does not return the number of rows affected by aSELECTstatement.
Instead, usePDO::query()to issue aSELECT COUNT(*)statement with the same predicates as your intendedSELECTstatement, then usePDOStatement::fetchColumn()to retrieve the number of rows that will be returned.
Your application can then perform the correct action.
If you already have a recordset, and want to know how many lines are in it, you'll have to fetch the data, using one of the fetch* methods ; and use count -- like you suggested.
mysqli in num_rows değişken ve karşılık gelen C API işlevi daha yakın olabilir, başka bir seçenek mysql_num_rows(). Yine sonuç tüm kayıtları saymak gerek kalmadan aynı bilgileri verir MySQL fonksiyonunu FOUND_ROWS() a> kullanmaktır.
Örnek:
$pdoDB->query('SELECT FOUND_ROWS()')->fetchColumn()