Dear Sir,

What's wrong with my code below. TQ.

<?php
mysql_connect("localhost", "warisanm_xxx", "xxx") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("warisanm_employee") or die(mysql_error());
echo "Connected to Database";


LOAD DATA INFILE "administrations/employee/salary/upload/marcsv.csv" INTO TABLE employee FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';


?>

    I assume you would like to run this script? Tell mysql to do something with it:

    $res = mysql_query(YOUR SCRIPT);

      In other words, this:

      LOAD DATA INFILE "administrations/employee/salary/upload/marcsv.csv" INTO TABLE employee FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';

      looks like a SQL query. PHP is not SQL, so you can't just throw a SQL query into a PHP script and expect PHP to know what to do with it.

      Furthermore, note that the entire [man]mysql[/man] plugin is quite outdated and has been deprecated in favor of [man]MySQLi[/man] (or [man]PDO[/man]). See the PHP manual page [man]mysqlinfo.api.choosing[/man] for more info about choosing which API to use.

        bradgrafelman;11001205 wrote:

        In other words, this:

        LOAD DATA INFILE "administrations/employee/salary/upload/marcsv.csv" INTO TABLE employee FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';

        looks like a SQL query. PHP is not SQL, so you can't just throw a SQL query into a PHP script and expect PHP to know what to do with it.

        Furthermore, note that the entire [man]mysql[/man] plugin is quite outdated and has been deprecated in favor of [man]MySQLi[/man] (or [man]PDO[/man]). See the PHP manual page [man]mysqlinfo.api.choosing[/man] for more info about choosing which API to use.

        Sir,

        Then how to run the code in server/ webpage. I want to upload .csv file into my MySQL database.

          <?php
          mysql_connect("localhost", "warisanm_xxxx", "xxxxx") or die(mysql_error());
          echo "Connected to MySQL<br />";
          mysql_select_db("warisanm_xxxe") or die(mysql_error());
          echo "Connected to Database";
          
          
          // Load CSV Data to MySQL table
          
          $res = mysql_query(LOAD DATA INFILE "administrations/employee/salary/upload/marcsv.csv" INTO TABLE employee FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';);
          or die(mysql_error());  
          echo "<a href='list_records.php'>View result</a>"; ?>

          The above code also didn't work...

            Because you're still just throwing SQL into the PHP script and expecting PHP to know what to do with it. [man]mysql_query[/man] (and the more modern interfaces) wants a string.

              <?php
              mysql_connect("localhost", "warisanmXXX", "XXXX07") or die(mysql_error());
              echo "Connected to MySQL<br />";
              mysql_select_db("warisanm_employee") or die(mysql_error());
              echo "Connected to Database";
              
              mysql_query(" LOAD DATA INFILE "administrations/employee/salary/upload/marcsv.csv" INTO TABLE employee FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
               ");
              
              
              
              echo "Insert File Into Table";
              ?>
              

                Look at what you've posted. There is a very strong clue there. You might also want to read up in the manual on strings.

                  Write a Reply...