LOAD DATA INFILE
Results 1 to 8 of 8

Thread: LOAD DATA INFILE

  1. #1
    Member
    Join Date
    Nov 2011
    Posts
    38

    LOAD DATA INFILE

    Dear Sir,

    What's wrong with my code below. TQ.

    PHP Code:
    <?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';


    ?>

  2. #2
    Beware: Crazy Scientist leatherback's Avatar
    Join Date
    Mar 2002
    Location
    Small border town between Netherlands and Germany
    Posts
    5,395
    I assume you would like to run this script? Tell mysql to do something with it:

    $res = mysql_query(YOUR SCRIPT);
    Php 4.* to 5.*. A small step for programmers. But a leap for me!

  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,429
    In other words, this:
    Code:
    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 mysql plugin is quite outdated and has been deprecated in favor of MySQLi (or PDO). See the PHP manual page mysqlinfo.api.choosing for more info about choosing which API to use.

  4. #4
    Member
    Join Date
    Nov 2011
    Posts
    38
    Quote Originally Posted by bradgrafelman View Post
    In other words, this:
    Code:
    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 mysql plugin is quite outdated and has been deprecated in favor of MySQLi (or PDO). See the PHP manual page mysqlinfo.api.choosing 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.

  5. #5
    Member
    Join Date
    Nov 2011
    Posts
    38

    Unhappy

    PHP Code:
    <?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...

  6. #6
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,885
    Because you're still just throwing SQL into the PHP script and expecting PHP to know what to do with it. mysql_query (and the more modern interfaces) wants a string.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  7. #7
    Member
    Join Date
    Nov 2011
    Posts
    38
    PHP Code:
    <?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";
    ?>

  8. #8
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,885
    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.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •