If I run this...

mysqlimport --host=host --user=user --ignore --fields-terminated-by=, --fields-enclosed-by=" database text.csv

...from the command line the correct table in the database is updated with the new values from the text file.

How do I send the same command using PHP? I have tried using exec(arguments) and passthru(arguments) with no success.

Using passthru shows that only the command as far as ..mysqlimport is run and the copyright info is passed back! Why are the arguments after mysqlimport not passed?

    • [deleted]

    Can you show us your code.

      4 days later

      Thanks for the interest Vincent...

      <?php
      if(isset($csvfile) && isset($table_name)){ // There is something to be transferred
      if (copy($csvfile,"csv_data\".$table_name.".csv")){
      printf("The file %s has been uploaded successfully and will now be processed. Please wait...<br>\n",$csvfile);
      include("../includes/globals.php");
      $mysql_command = "e:\progra~1\mysql\bin\mysqlimport --host=localhost --user=root --ignore --fields-terminated-by=, --fields-enclosed-by=\" database tbl_sites.csv";
      $import = passthru($mysql_command);
      } else {
      printf("There has been an error with the file transfer, you will need to try again<br>\n");
      }
      } else { // Create csv_transfer form

      ..and so on..

      You will notice I am testing on my local server before trying online. As I said, the command seems to run up to 'mysqlimport' but the arguments are not passed. When I echo $mysql_command the code looks correct!

      BTW: W2k, PHP4, MySQL 3.23, Xitami (Online host = Linux server).

      Really appreciate your help.

        Thanks for the interest Vincent...

        <?php
        if(isset($csvfile) && isset($table_name)){ // There is something to be transferred
        if (copy($csvfile,"csv_data\".$table_name.".csv")){
        printf("The file %s has been uploaded successfully and will now be processed. Please wait...<br>\n",$csvfile);
        include("../includes/globals.php");
        $mysql_command = "e:\progra~1\mysql\bin\mysqlimport --host=localhost --user=root --ignore --fields-terminated-by=, --fields-enclosed-by=\" database tbl_sites.csv";
        $import = passthru($mysql_command);
        } else {
        printf("There has been an error with the file transfer, you will need to try again<br>\n");
        }
        } else { // Create csv_transfer form

        ..and so on..

        You will notice I am testing on my local server before trying online. As I said, the command seems to run up to 'mysqlimport' but the arguments are not passed. When I echo $mysql_command the code looks correct!

        BTW: W2k, PHP4, MySQL 3.23, Xitami (Online host = Linux server).

        Really appreciate your help.

          • [deleted]

          Have you tried replacing this with the 'full' name?

          e:\progra~1\

            I tried that first but it fell because of the space between 'program' and 'files'. However, the command mysqlimport is transmitted to the server, it is the arguments after the command that are not passed.

            Using 'passthru' returns the copyright and help info into the html, as would happen if you entered 'mysqlimport' into the command line directly.

              Write a Reply...