473,466 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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_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

Jul 17 '05 #1
8 1699
ne**@celticbear.com wrote:
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.


chmod is a PHP function.

Jul 17 '05 #2

Daniel Tryba wrote:
ne**@celticbear.com wrote:
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.


chmod is a PHP function.


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

Jul 17 '05 #3

n...@celticbear.com wrote:
Daniel Tryba wrote:


chmod is a PHP function.


http://us3.php.net/manual/en/function.chmod.php
Huh. Lookeedere. Had no idea. Thanks!


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

Jul 17 '05 #4
ne**@celticbear.com wrote:
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


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

NM

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #5
News Me wrote:
Why use PHP? mysqlimport (included with MySQL) can handle that for you.

NM


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

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #6
ne**@celticbear.com wrote:

[snip]
$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>";

[snip]

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

NM

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #7
ne**@celticbear.com wrote:

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.


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

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #8
I noticed that Message-ID: <11*************@corp.supernews.com> from
News Me contained the following:
$result = @mysql_query($sql, $dbh) or $error_msg .= "<div
align=\"center\" class=\"tah12RedBold\">".mysql_error()."</div>";

[snip]

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


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/
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frank Pryor | last post by:
Hello, I'd appreciate suggestions as I hash out my idea. Perhaps I'm going about this the wrong way. I have users using a third party windows application. They can export data from this...
1
by: Astra | last post by:
Hi All Could you please let me know how my ASP page can insert 1 row of data containing line breaks into a MySQL DB. To explain, I'm using ASP Classic > MyODBC 3.5x (Win) > MySQL 4 (Win) and...
6
by: Raqueeb Hassan | last post by:
Hello There! Have you guys tried inserting variables in mySQL tables? Do I have to use 'quote' as we had been doing to insert strings? mysql> INSERT INTO occurrence (word_id,page_id) VALUES...
7
by: Dennis Gearon | last post by:
I've been using PG very lightly for quite awhile, (although I"ve read through all but the programmer's manual once or twice). I loved when I got to PG and it had Oracle like features, "A real...
2
by: kokul_k | last post by:
Hi.. I'm facing a problem during inserting records in Mysql database. My table consists of 9 fields. When i try to insert 1000 records to this table using for loop it takes a lot of time.. nearly...
1
Ajm113
by: Ajm113 | last post by:
Ok, when I was new to this I had this problem and I bet a lot of other people did when they where new to PHP and Mysql. So this mite be your question; "Ok, no errors or warnings in mysql and php so...
1
by: djmeltdown | last post by:
I'm having trouble getting a foreach() loop to insert a record into a MySQL Database. Which I've never had any trouble before, it just seems quirky. I've tried the mysql_query statement without a...
3
by: len | last post by:
Hi All I have started a little pet project to learn python and MySQL. The project involves figuring out all the combinations for a 5 number lottery and storing the data in a MySQL file. The...
6
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.