Counting strings reached PDO


I'm doing a query and need to count the number of rows returned, I'm not usually accustomed to doing this in PDO, follow my code below.

$sqlCODCEL = $conn->prepare("SELECT * FROM tbl_CELULAS WHERE TXT_CODIG_SECUR = :codCEL");
$sqlCODCEL->bindParam(":codCEL", $lbl_CODCELULA);
$linha = $sqlCODCEL->fetchAll();
$count = count_chars($linha);

asked by anonymous 24.08.2015 / 13:47

2 answers


In order for you to return the amount of affected rows, you have to use rowCount(); . Home Probably $linhasafetadas = $sqlCODCEL->rowCount() will solve your problem.

An example:
/* Delete all rows from the FRUIT table */
$del = $dbh->prepare('DELETE FROM fruit');

/* Return number of rows that were deleted */
print("Return number of rows that were deleted:\n");
$count = $del->rowCount();
print("Deleted $count rows.\n");



Return number of rows that were deleted:   Deleted 9 rows.


24.08.2015 / 13:58

Use the method rowCount () it returns the rows affected by a DML (insert, update delete ) in some databases also returns the rows of a select, in mysql it works correctly.

$linhas =$sqlCODCEL->rowCount();


How to get the number of rows from a select with SQL Server.

24.08.2015 / 13:53