PHP Function pg_num_rows
The php function pg_num_rows takes a result-set variable as an argument. It returns the number of rows in that variable, or -1 on error.
In the above example, the first setAttribute() line tells PDO to use real prepared statements (which separate the statement and data parts so that the data never gets parsed by SQL, giving a possible attacker a chance to inject malicious SQL). It also disables query caching in PDO, which can be useful when working with large queries.
Another option is to use a function like pg_fetch_result(), which is a better choice than pg_num_rows if you want to know how many rows the query affects (and only the affected rows, not all of the rows that were returned by the query). It requires that the query be in a transaction and that there are no BEGIN/COMMIT commands included in the query string, which may reduce performance.
The function expects a PostgreSql