Connecting Tech Pros Worldwide Forums | Help | Site Map

need help inserting a CSV into mySQL via PHP page.

news@celticbear.com
Guest
 
Posts: n/a
#1: Jul 17 '05
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_produpload` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES
TERMINATED BY '\r\n'";
$result = @mysql_query($sql, $dbh) or $error_msg .= "<div
align=\"center\" class=\"tah12RedBold\">".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
Guest
 
Posts: n/a
#2: Jul 17 '05

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.

news@celticbear.com
Guest
 
Posts: n/a
#3: Jul 17 '05

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]

http://us3.php.net/manual/en/function.chmod.php
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

news@celticbear.com
Guest
 
Posts: n/a
#4: Jul 17 '05

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

News Me
Guest
 
Posts: n/a
#5: Jul 17 '05

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_produpload` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES
> TERMINATED BY '\r\n'";
> $result = @mysql_query($sql, $dbh) or $error_msg .= "<div
> align=\"center\" class=\"tah12RedBold\">".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
News Me
Guest
 
Posts: n/a
#6: Jul 17 '05

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
News Me
Guest
 
Posts: n/a
#7: Jul 17 '05

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_produpload` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES
> TERMINATED BY '\r\n'";
> $result = @mysql_query($sql, $dbh) or $error_msg .= "<div
> align=\"center\" class=\"tah12RedBold\">".mysql_error()."</div>";[/color]
[snip]

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

NM

--
convert UPPERCASE NUMBER to a numeral to reply
News Me
Guest
 
Posts: n/a
#8: Jul 17 '05

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
Geoff Berrow
Guest
 
Posts: n/a
#9: Jul 17 '05

re: need help inserting a CSV into mySQL via PHP page.


I noticed that Message-ID: <111gdlkon1c802b@corp.supernews.com> from
News Me contained the following:
[color=blue][color=green]
>> $result = @mysql_query($sql, $dbh) or $error_msg .= "<div
>> align=\"center\" class=\"tah12RedBold\">".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/
Closed Thread