-1

i use rowCount() php function to get number of my PDO query. but the issue is that this function Calculate deleted items from database.

i want to get number of exist items in DB without deleted items.

tanks

moosavi
  • 174
  • 1
  • 2
  • 12
  • from php doc PDOStatement::rowCount — Returns the number of rows affected by the last SQL statement http://php.net/manual/en/pdostatement.rowcount.php – ScaisEdge Dec 06 '16 at 14:34
  • Limit your query with a `WHERE` clause. – aynber Dec 06 '16 at 14:34
  • Can you elaborate a bit more on what you mean and show a minimal example which demonstrates the problem? – David Dec 06 '16 at 14:34

2 Answers2

2

You cannot delete rows and get their remaining number in a single query. Make another query like SELECT COUNT(*) FROM table_name.

vuryss
  • 1,270
  • 8
  • 16
2

PDOStatement::rowCount is meant to count the rows affected by DELETE, INSERT, or UPDATE queries.

If you want to get the number of rows returned by a SELECT query, then you can do it with a SELECT COUNT(*) statement. No need to use rowCount at all.

From the documentation:

For most databases, PDOStatement::rowCount() does not return the number of rows affected by a SELECT statement.

Federkun
  • 36,084
  • 8
  • 78
  • 90