0

trying to get the affected row return 0 file contain 250k records:

$affectedRows = 0; $affectedRows = $pdo->exec( "DELETE FROM tablename WHERE Col3 BETWEEN '2018-01-01 00:00:00' AND '2018-01-31 00:00:00'; ALTER TABLE tablename AUTO_INCREMENT = 1; LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE tablename FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ' ( `Col1`, `Col2`, `Col3`)"); echo var_dump($affectedRows); 

Store the CSV but Return 0

7
  • Where is $affectedRows from. What is vardump? Commented Sep 14, 2018 at 20:29
  • 1
    PDO doesn't allow you to execute multiple queries with a single $pdo->exec() call. Commented Sep 14, 2018 at 20:35
  • 1
    You're also missing quotes around the argument to exec(). Commented Sep 14, 2018 at 20:36
  • @JNevill you see this line echo vardump($affectedRows); ??? And Vardump is the metod to outpud the return data. Commented Sep 14, 2018 at 21:15
  • I though it was var_dump() but I don't write much pho anymore so perhaps I'm wrong. Commented Sep 14, 2018 at 21:18

1 Answer 1

1

Solved with:

This script is full suported:

LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE tablename FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ' ( `Col1`, `Col2`, `Col3`) 

But i merge it with other in some Query Like that:

DELETE FROM tablename WHERE date BETWEEN '$Date1' AND '$Date2'; ALTER TABLE tbalename AUTO_INCREMENT = 1; LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE tablename FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ' ( `Col1`, `Col2`, `Col3`); 

this is wrong, becouse $PDO->exec() Cant return the number of affected table or rows.

Instead of it, to solve i need past an array, becouse my script support it like that:

$stmtpre[1] = "DELETE FROM tablename WHERE date BETWEEN '$Date1' AND '$Date2';"; $stmtpre[2] = "ALTER TABLE tbalename AUTO_INCREMENT = 1;"; $stmtpre[3] = "LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE tablename FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ' ( `Col1`, `Col2`, `Col3`);"; 

Same this: https://stackoverflow.com/a/52370701/9632001

Sign up to request clarification or add additional context in comments.

Comments