LOAD DATA INFILE error in php
EDIT : You are mixing two plugins MYSQL and MYSQLi in same script, below i dumped remaining part of your code using mysqli plugin, because your upper part uses mysqli...
N.B:You can't do that. Pick just any single API.
$result = mysqli_query($connection, $sql);
if (mysqli_affected_rows($connection) >= 1) {
$message = "The trip was successfully inserted!";
} else {
$message = "The trip insert failed";
$message .= mysqli_error($connection);
}
load data infile is not working
You tried to use "LOAD DATA LOCAL INFILE"?
LOAD DATA LOCAL INFILE 'abc.csv' INTO TABLE abc
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(col1, col2, col3, col4, col5...);
In your case:
$sql = "LOAD DATA LOCAL INFILE '$filepath'
INTO TABLE customers
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY ',,,\\r\\n'
IGNORE 1 LINES
(name, email)";
$this->Customer->query($sql);
"If LOCAL is specified, the file is read by the client program on the client host and sent to the server." from Documentation
Answered in https://stackoverflow.com/a/14133740/2925795
LOAD DATA LOCAL INFILE fails - from php, to mysql (on Amazon rds)
I've given up on this, as I think it's a bug in php - in particular the mysql_connect code, which is now deprecated. It could probably be solved by compiling php yourself with changes to the source using steps similar to those mentioned in the bug report that @eggyal mentioned: https://bugs.php.net/bug.php?id=54158
Instead, I'm going to work around it by doing a system() call and using the mysql command line:
$sql = "LOAD DATA LOCAL INFILE '$csvPathAndFile' INTO TABLE $tableName FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\\"' ESCAPED BY '\\\\\\\\' LINES TERMINATED BY '\\\\r\\\\n';";
system("mysql -u $dbUser -h $dbHost --password=$dbPass --local_infile=1 -e \"$sql\" $dbName");
That's working for me.
Related Topics
Calling Function Inside Preg_Replace Thats Inside a Function
How to Read Gzip-Ed Response from Stackoverflow API in PHP
Using PHP to Execute Multiple MySQL Queries
PHP Variable Inside Echo 'HTML Code'
Replace Woocommerce_Add_Order_Item_Meta Hook in Woocommerce 3.4
Reverse the Letters in Each Word of a String
Simple PHP SQL Login Troubleshooting
Calling Stored Procedure with Out Parameter Using Pdo
How to Count Query Result Rows
Syntax Error While Defining an Array as a Property of a Class
Variable Position in Comparision in PHP
Pass Arraylist Bean from Android to Webservice PHP
Integrating Mailjet API V3 Wrapper as Codeigniter Library
Concatenation with Addition in It Doesn't Work as Expected
What Does This Mean in PHP: -> or =>