Load Data Local Infile Forbidden In... PHP

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



Leave a reply



Submit