V
V
Viktor Yanyshev2016-12-14 19:32:49
PHP
Viktor Yanyshev, 2016-12-14 19:32:49

How to find out how many rows have been added to the database?

I get an array of users from AD and write this array to the database through a loop. The table has an ad_id column where a unique user code from AD is recorded, the column itself can only have a unique value, so if 5 users come again, it throws an error, oh, ad_id is not unique and does not record anything. If you send 6 users, then 5 users will not be recorded, but 1 user will be added to the database, but an error will be displayed on the screen about the non-uniqueness of the data.
Tell,

  1. How can I find out how many rows have been added to the database (SQLite3)?
  2. How many rows have been added to the database, with the exception of those that are already in the database?
  3. Provided that the column in the database table will not let you write down the user if his ad_id is not unique, under this condition, is it necessary to do an additional check for the uniqueness of the user?
UPD:
...the table already has an "id INT AI" column + an "ad_id INT UNIQUE" column. "DBMS don't work like that" - while after recording (for example: synchronization with 1C, import from CSV/XML/xlsx etc) in the database, output data, Total: N; Repetitions: N; Added: N; Not added: N; Updated: N. With the addition and not the addition, it seems more or less presented, just each false from execute plus the counter and for each true, I also add a counter, with consequences for Everything. And what about Updated, Repeats? While writing, it seems like I answered my own questions, almost :)"...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2016-12-14
@dimonchik2013

INSERT IGNORE will allow you not to suffer garbage

M
Max, 2016-12-14
@MaxDukov

1. Count after, minus Count before - that's how much was inserted for you
2. I didn't understand, how does this differ from question 1?
3. no. The DB itself will not write.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question