P
P
Pavel2016-06-20 15:59:04
Drupal
Pavel, 2016-06-20 15:59:04

How to pass parameter local-infile=1 in drupal 7?

In general, the situation is as follows, there is a CSV file - approximately 200,000 lines (in principle, not the point), you need to quickly upload it to a Mysql table.
Accordingly, a form has been made that, by submission, must execute this query through db_query ()

db_query("
    LOAD DATA LOCAL INFILE 'http://sitename.com/sites/default/files/example/example.csv' 
    INTO table example_table
    CHARACTER SET 'UTF8'
    FIELDS TERMINATED BY ';' 
    LINES TERMINATED BY '\r\n' 
    IGNORE 1 LINES
  ");

Now the problem is, if you use it directly through PhpMyAdmin, then the request is processed, the export passes. But after submitting - the site goes into error, the logs are empty! I talked with the provider, suggested that I pass the local-infile flag when connecting to the database, I thought to pass it to db_query()
db_query("
    LOAD DATA LOCAL INFILE 'http://sitename.com/sites/default/files/example/example.csv' 
    INTO table example_table
    CHARACTER SET 'UTF8'
    FIELDS TERMINATED BY ';' 
    LINES TERMINATED BY '\r\n' 
    IGNORE 1 LINES
  ", array('local-infile' => true));

But it didn't work. There is no access to my.cnf. Maybe someone has some ideas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikit Khaner, 2016-07-01
@Nikit

www.zimplicit.se/en/knowledge/drupal-6-and-load-da...

$connection = mysqli_init();
  mysqli_options($connection, MYSQLI_OPT_LOCAL_INFILE, true); //added to be able to run LOAD DATA LOCAL INFILE
  @mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question