need help inserting a CSV into mySQL via PHP page.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news@celticbear.com

    need help inserting a CSV into mySQL via PHP page.

    I'm building an e-commerce site, where the owner needs to be able to
    upload a CSV file of product that gets inserted into mySQL.
    Unfortunately, I think my Web host may have some functions turned off.
    Is there some other ways I can try to do the following?

    First, I'm using a form to upload a file. That works, but it sets the
    file permissions to 600, and the PHP command "exec()" is disabled so I
    can't chmod it as part of the script.

    But that's OK I guess. I can still FTP the file up and change the
    permissions to even 777 if need be. The real problem comes when trying
    to do the insert:

    $sql = "LOAD DATA INFILE
    '/home/myaccount/public_html/data/item_test.csv' INTO TABLE
    `tbl_temp_produ pload` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES
    TERMINATED BY '\r\n'";
    $result = @mysql_query($s ql, $dbh) or $error_msg .= "<div
    align=\"center\ " class=\"tah12Re dBold\">".mysql _error()."</div>";

    I'm getting no error message, but it's not inserting either.
    I can use phpMyAdmin to manually insert the file off my local PC, but I
    just can't get it to do it from the file on the server.

    Is there another way to do this? (No I can't give phpMyAdmin access to
    the user.)

    Thanks for any suggestions!
    Liam

  • Daniel Tryba

    #2
    Re: need help inserting a CSV into mySQL via PHP page.

    news@celticbear .com wrote:[color=blue]
    > First, I'm using a form to upload a file. That works, but it sets the
    > file permissions to 600, and the PHP command "exec()" is disabled so I
    > can't chmod it as part of the script.[/color]

    chmod is a PHP function.

    Comment

    • news@celticbear.com

      #3
      Re: need help inserting a CSV into mySQL via PHP page.


      Daniel Tryba wrote:[color=blue]
      > news@celticbear .com wrote:[color=green]
      > > First, I'm using a form to upload a file. That works, but it sets[/color][/color]
      the[color=blue][color=green]
      > > file permissions to 600, and the PHP command "exec()" is disabled[/color][/color]
      so I[color=blue][color=green]
      > > can't chmod it as part of the script.[/color]
      >
      > chmod is a PHP function.[/color]


      Huh. Lookeedere. Had no idea. Thanks!

      OK, well, I still have the most important problem of not being able to
      use the mySQL command: "LOAD DATA INFILE".
      Any workarounds or tips on that?

      Thanks!
      Liam

      Comment

      • news@celticbear.com

        #4
        Re: need help inserting a CSV into mySQL via PHP page.


        n...@celticbear .com wrote:[color=blue]
        > Daniel Tryba wrote:[/color]
        [color=blue][color=green]
        > >
        > > chmod is a PHP function.[/color]
        >
        > http://us3.php.net/manual/en/function.chmod.php
        > Huh. Lookeedere. Had no idea. Thanks!
        >[/color]

        Drat, got my hopes up:

        Warning: chmod(): Permission denied in
        /home/iestud/public_html/gto/admin/upload.php on line 22

        Oh well, I can still FTP the file up and chmod it using the FTP
        program.
        Thanks

        Comment

        • News Me

          #5
          Re: need help inserting a CSV into mySQL via PHP page.

          news@celticbear .com wrote:[color=blue]
          > I'm building an e-commerce site, where the owner needs to be able to
          > upload a CSV file of product that gets inserted into mySQL.
          > Unfortunately, I think my Web host may have some functions turned off.
          > Is there some other ways I can try to do the following?
          >
          > First, I'm using a form to upload a file. That works, but it sets the
          > file permissions to 600, and the PHP command "exec()" is disabled so I
          > can't chmod it as part of the script.
          >
          > But that's OK I guess. I can still FTP the file up and change the
          > permissions to even 777 if need be. The real problem comes when trying
          > to do the insert:
          >
          > $sql = "LOAD DATA INFILE
          > '/home/myaccount/public_html/data/item_test.csv' INTO TABLE
          > `tbl_temp_produ pload` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES
          > TERMINATED BY '\r\n'";
          > $result = @mysql_query($s ql, $dbh) or $error_msg .= "<div
          > align=\"center\ " class=\"tah12Re dBold\">".mysql _error()."</div>";
          >
          > I'm getting no error message, but it's not inserting either.
          > I can use phpMyAdmin to manually insert the file off my local PC, but I
          > just can't get it to do it from the file on the server.
          >
          > Is there another way to do this? (No I can't give phpMyAdmin access to
          > the user.)
          >
          > Thanks for any suggestions!
          > Liam
          >[/color]

          Why use PHP? mysqlimport (included with MySQL) can handle that for you.

          NM

          --
          convert UPPERCASE NUMBER to a numeral to reply

          Comment

          • News Me

            #6
            Re: need help inserting a CSV into mySQL via PHP page.

            News Me wrote:[color=blue]
            > Why use PHP? mysqlimport (included with MySQL) can handle that for you.
            >
            > NM[/color]

            I should have actually read the ENTIRE post. NEVER MIND...

            --
            convert UPPERCASE NUMBER to a numeral to reply

            Comment

            • News Me

              #7
              Re: need help inserting a CSV into mySQL via PHP page.

              news@celticbear .com wrote:

              [snip][color=blue]
              > $sql = "LOAD DATA INFILE
              > '/home/myaccount/public_html/data/item_test.csv' INTO TABLE
              > `tbl_temp_produ pload` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES
              > TERMINATED BY '\r\n'";
              > $result = @mysql_query($s ql, $dbh) or $error_msg .= "<div
              > align=\"center\ " class=\"tah12Re dBold\">".mysql _error()."</div>";[/color]
              [snip]

              What is the '@' in front of mysql_query() for?

              NM

              --
              convert UPPERCASE NUMBER to a numeral to reply

              Comment

              • News Me

                #8
                Re: need help inserting a CSV into mySQL via PHP page.

                news@celticbear .com wrote:[color=blue]
                >
                > I'm getting no error message, but it's not inserting either.
                > I can use phpMyAdmin to manually insert the file off my local PC, but I
                > just can't get it to do it from the file on the server.
                >[/color]

                There may be errors in the web server's (apache?) error log.

                --
                convert UPPERCASE NUMBER to a numeral to reply

                Comment

                • Geoff Berrow

                  #9
                  Re: need help inserting a CSV into mySQL via PHP page.

                  I noticed that Message-ID: <111gdlkon1c802 b@corp.supernew s.com> from
                  News Me contained the following:
                  [color=blue][color=green]
                  >> $result = @mysql_query($s ql, $dbh) or $error_msg .= "<div
                  >> align=\"center\ " class=\"tah12Re dBold\">".mysql _error()."</div>";[/color]
                  >[snip]
                  >
                  >What is the '@' in front of mysql_query() for?[/color]

                  Is that a rhetorical question?

                  --
                  Geoff Berrow (put thecat out to email)
                  It's only Usenet, no one dies.
                  My opinions, not the committee's, mine.
                  Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                  Comment

                  Working...