Forum Moderators: open

Message Too Old, No Replies

PhpMyadmin error

         

sfast

10:27 pm on Sep 17, 2007 (gmt 0)

10+ Year Member



I am trying to use phpMyAdmin to import a csv file of 8000 records in a table.

idFirstNameDateOfBirthCellPhoneAge
1PAT 9/13/1947504621146859
2EDNA 4/24/1976 30
3CATINA 9/3/1972 504975773034

Number of records(queries) to skip from start = 0

CSV using LOAD DATA

Fields terminated by \t
Fields enclosed by "
Fields escaped by \
Lines terminated by auto

Column names id,FirstName,DateOfBirth,CellPhone, Age

---------------------------------------------------------------
LOAD DATA INFILE '/tmp/phpUyInJ6' INTO TABLE `dcn` FIELDS TERMINATED BY '\t' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'(

`DCN_id` , `FirstName` , `DateOfBirth` , `CellPhone` , `Age` )

MySQL said:

#1045 - Access denied for user 'fasttaxs'@'localhost' (using password: YES)
------------------------------------------------------------------

Why do I get this error?
Any help is appreciated.

Thankyou

sfast

1:56 pm on Sep 18, 2007 (gmt 0)

10+ Year Member



Somebody please help.

jatar_k

2:10 pm on Sep 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it sounds like the user doesn't have the appropriate permissions

sfast

3:03 pm on Sep 18, 2007 (gmt 0)

10+ Year Member



Thanks for responding.

I am trying to use below script.
But it shows me error
-
insert into DCN values ('1,PAT,9/13/1947,5046211468,59,,7.23243E+11,No,PURDY ')
Column count doesn't match value count at row 1
It does not separate the columns using '\t'

What is wrong here.
-----------------------------------------------------------

$fcontents = file ('returningClients.csv');
# expects the csv file to be in the same dir as this script

for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i], '\t');
$arr = explode("\t", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','

$sql = "insert into DCN values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}

jatar_k

3:05 pm on Sep 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> Column count doesn't match value count at row 1

insert into DCN values ('1,PAT,9/13/1947,5046211468,59,,7.23243E+11,No,PURDY ')

in the above you are inserting all of that as a single row, is that your intention?

if not then you need single quotes around each individual value

sfast

3:47 pm on Sep 18, 2007 (gmt 0)

10+ Year Member



Thanks for replying jatar_k

No that is not what I want.
I wanted
insert into DCN values
(1,'PAT',9/13/1947,5046211468,59,,7.23243E+11,'No','PURDY')

When I change '/t' to ',' it accepts, but in the below way.

insert into DCN values ('1','PAT','5046211468','59','','7.23243E+11','No','PURDY ')
Data truncated for column 'DCN' at row 1

column DCN is BigINT(20)
Why wouldnt it accept it?

jatar_k

3:50 pm on Sep 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if DCN is a column then that syntax is wrong. You need to have the tablename there and then name the columns after

maybe take a look at this for syntax
[dev.mysql.com...]

sfast

4:00 pm on Sep 18, 2007 (gmt 0)

10+ Year Member



I changed column name DCN to DCNNO.
It still does not accept DCNNO.

I think It will if I change it to varchar

insert into DCN values ('1','PAT','5046211468','59','','7.23243E+11','No','PURDY ')
Data truncated for column 'DCNNO' at row 1

The value for DCNNO = 723243040617.
But in CSV file, it displays like - 7.23243E+11.


When I manually insert the above row, it shows no erros.
insert into DCN (dcn_id, FirstName, CellPhone, Age, emailAddress, DCNNO,IRAL, Lastname) values ('1','PAT','5046211468','59','',723243040617,'No','PURDY
');

jatar_k

4:02 pm on Sep 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> But in CSV file, it displays like - 7.23243E+11.

as you can see, that won't work, a varchar swap would fix it

could you open the csv in excel and play with the column format and change them all to the full number?

sfast

4:17 pm on Sep 18, 2007 (gmt 0)

10+ Year Member



Thanks jatar_k.
Many Many thanks.

I was able to import the file.

jatar_k

4:18 pm on Sep 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



good stuff

did you use the varchar change or excel?

sfast

4:27 pm on Sep 18, 2007 (gmt 0)

10+ Year Member



Copied the DCNNO column from .xls to .csv file and then saved it.

This time the column did not change to a different format.

No change with varchar.

Thanks.