php - Load data infile default value not inserting in table -


i'm importing csv file using load datainfile

the csv columns name,type,status

my table structure

 name  : varchar type  : varchar status: tiny int default value 1 

i use stmt :

load data infile '/var/www/names.csv'  table users fields terminated ',' enclosed '"' lines terminated '\n' ignore 1 lines  

when use above statement has insert status value 1 each row, not inserting same. please advise.

when loading file, mysql expects has same number of columns destination table, unless specify otherwise, if missing column has default value. supply column list load statement, , literal 1 value of status:

load data infile '/var/www/names.csv'  table users    fields terminated ','    enclosed '"'    lines terminated '\n'    ignore 1 lines    (`name`, `type`, 1) 

you can set clause:

load data infile '/var/www/names.csv'  table users    fields terminated ','    enclosed '"'    lines terminated '\n'    ignore 1 lines    (`name`, `type`)   set `status` = 1 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -