help : LOAD DATA LOCAL INFILE

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default help : LOAD DATA LOCAL INFILE


    I'm trying to load a local file in to a database and have had no luck.


    I have downloaded the table contents (1row) using phpAdmin and changed the id# and one
    other field before trying to upload. To test out the script.

    That file looks like this (dbdata.txt)

    "2","public","company2","contact","street","suite" ,"city","province","postcode","countr
    y","phone","fax","region","service","first name","surname","create date"


    The script i'm trying to use looks like this.

    $loadfile = "LOAD DATA LOCAL INFILE 'dbdata.txt' INTO TABLE tablename FIELDS TERMINATED
    BY ',' ENCLOSED BY '\"'";
    $result = mysql_query($loadfile) or die (" Invalid DATA LOAD query");

    Both files are in the same directory and I am able to connect to the table and query it
    within the rest of the script.

    Any help you can give on this is appreciated.

    Thanks,




    Dave Guest

  2. Similar Questions and Discussions

    1. LOAD DATA INFILE problem
      Consider the following table and csv file: ------------------------------------------- CREATE TABLE `table_test` ( `c1` VARCHAR( 255 ) NOT NULL...
    2. LOAD DATA INFILE
      Hello ng, I'm trying to do this mysql query but I receive an error. Can someone help me? LOAD DATA INFILE...
    3. Complex LOAD DATA INFILE
      Dear mysql-ians, I am using mysql 5.0 and I want to load a huge txt-file in my database. My text file (file.txt) looks like: col1 col2 col3...
    4. Load Data Infile question
      I just tried to execuete a Load Data Infile command to import data from a .cvs file into a mysql table, but I get the following error. Any help at...
    5. LOAD DATA LOCAL INFILE and Perl DBI/DBD
      HI all, For the past several months we have been using LOAD DATA LOCAL INFILE to bulk load tables within Perl modules. Recently, someone...
  3. #2

    Default Re: help : LOAD DATA LOCAL INFILE

    Dave wrote:
    > I'm trying to load a local file in to a database and have had no luck.

    Try asking the MySQL server first - it should help point you in the right
    direction.

    $result = mysql_query($loadfile)
    or die ("Error ".mysql_errno() ." : ".mysql_error() ."");


    > I have downloaded the table contents (1row) using phpAdmin and
    > changed the id# and one other field before trying to upload. To test
    > out the script.
    >
    > That file looks like this (dbdata.txt)
    >
    >
    "2","public","company2","contact","street","suite" ,"city","province","postco
    de","countr
    > y","phone","fax","region","service","first name","surname","create
    > date"
    >
    >
    > The script i'm trying to use looks like this.
    >
    > $loadfile = "LOAD DATA LOCAL INFILE 'dbdata.txt' INTO TABLE tablename
    > FIELDS TERMINATED BY ',' ENCLOSED BY '\"'";
    > $result = mysql_query($loadfile) or die (" Invalid DATA LOAD query");

    This is what phpMyAdmin generated for a similar csv file:

    $loadfile=
    'LOAD DATA LOCAL INFILE
    \'/path-to-your-server/dbdata.csv\' INTO TABLE
    `tablename`
    FIELDS TERMINATED BY \',\' ENCLOSED BY \'"\'
    ESCAPED BY \'\\\\\' LINES TERMINATED BY \'\\r\\n\'';

    // cue the result or tell us why not..
    $result = mysql_query($loadfile)
    or die ("Error ".mysql_errno() ." : ".mysql_error() ."");


    Note the path-to-your-server may be something like
    /home/htdocs/xxxxx/dbdata.txt


    Hope that helps

    --
    Tony


    Tony Guest

  4. #3

    Default Re: help : LOAD DATA LOCAL INFILE

    On Mon, 04 Oct 2004 14:42:57 -0500, [email]me@here.com[/email] (Dave) wrote:
    >I'm trying to load a local file in to a database and have had no luck.
    >
    >
    >I have downloaded the table contents (1row) using phpAdmin and changed the id# and one
    >other field before trying to upload. To test out the script.
    >
    >That file looks like this (dbdata.txt)
    >
    >"2","public","company2","contact","street","suite ","city","province","postcode","countr
    >y","phone","fax","region","service","first name","surname","create date"
    >
    >
    >The script i'm trying to use looks like this.
    >
    >$loadfile = "LOAD DATA LOCAL INFILE 'dbdata.txt' INTO TABLE tablename FIELDS TERMINATED
    >BY ',' ENCLOSED BY '\"'";
    >$result = mysql_query($loadfile) or die (" Invalid DATA LOAD query");
    >
    >Both files are in the same directory and I am able to connect to the table and query it
    >within the rest of the script.
    You haven't said what problems you're having. Use mysql_error() to get an
    error message, and post this message.

    Actually - put the error message into Google first - you are likely hitting
    the security constraints placed on LOAD DATA LOCAL INFILE by MySQL itself.

    --
    Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
    Andy Hassall Guest

  5. #4

    Default Re: help : LOAD DATA LOCAL INFILE

    In article <rkk3m05f2m77m86jhfoiphgn21gbvj1bcg@4ax.com>, [email]andy@andyh.co.uk[/email]
    says...
    >
    >On Mon, 04 Oct 2004 14:42:57 -0500, [email]me@here.com[/email] (Dave) wrote:
    >
    >>I'm trying to load a local file in to a database and have had no luck.
    >>
    >>
    >>I have downloaded the table contents (1row) using phpAdmin and changed the
    id# and one
    >>other field before trying to upload. To test out the script.
    >>
    >>That file looks like this (dbdata.txt)
    >>
    >>"2","public","company2","contact","street","suit e","city","province","postco
    de","countr
    >>y","phone","fax","region","service","first name","surname","create date"
    >>
    >>
    >>The script i'm trying to use looks like this.
    >>
    >>$loadfile = "LOAD DATA LOCAL INFILE 'dbdata.txt' INTO TABLE tablename FIELDS
    TERMINATED
    >>BY ',' ENCLOSED BY '\"'";
    >>$result = mysql_query($loadfile) or die (" Invalid DATA LOAD query");
    >>
    >>Both files are in the same directory and I am able to connect to the table
    and query it
    >>within the rest of the script.
    >
    > You haven't said what problems you're having. Use mysql_error() to get an
    >error message, and post this message.
    >
    > Actually - put the error message into Google first - you are likely hitting
    >the security constraints placed on LOAD DATA LOCAL INFILE by MySQL itself.
    >
    >--
    >Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    ><http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool


    I added the script above and the error i'm getting is.

    Error 1148 : The used command is not allowed with this MySQL version

    Thanks again


    Dave Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139