Count how many rows loaded LOAD DATA INFILE

I have a text file with names in the following format,

firstname:lastname

Here is the query that I run,

$this->db->query("LOAD DATA INFILE 'names.txt' INTO TABLE names FIELDS TERMINATED BY ':' (firstname, lastname)");

How can I calculate how many rows were inserted?

+3
source share
3 answers

from the manual

When the LOAD DATA INFILE statement ends, it returns string information in the following format:

Records: 1  Deleted: 0  Skipped: 0  Warnings: 0

If you use the C API, you can get approval information by calling the mysql_info () function.

try using mysql_info ()

like:

 $info_str = mysql_info($$link);
    if (ereg("Records: ([0-9]*)", $info_str, $count) == false) {
        ereg("Rows matched: ([0-9]*)", $info_str, $count);
    }
+2
source

You can run the following query:

 SELECT ROW_COUNT()

He will answer your question.

0
source

@rkosegi - ROW_COUNT () only works with SQL_CALC_FOUND_ROWS in SELECT statements.

0
source

Source: https://habr.com/ru/post/1789695/


All Articles