load data infile

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

load data infile

Post by bouncer »

hi there,

how can i set in the @datafield2 the value in $doc_date, so every time that i run the php script it set the date of server.

this is just an example of what i want to do ...

Code: Select all

 
$doc_date = date('Y-m-d');
 
LOAD DATA INFILE 'example.csv' REPLACE INTO TABLE `content`
                FIELDS TERMINATED BY ';'
                OPTIONALLY ENCLOSED BY ''
                LINES TERMINATED BY '\n'
                (`ref`, @datefield1, @datefield2)
                SET 
                `status_date` = STR_TO_DATE(@datefield1, '%d/%m/%Y'),
                `doc_date` = ????;
 
thanks in advance
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: load data infile

Post by ghurtado »

Could you do something like the following?

Code: Select all

$sql = " ... `status_date` = STR_TO_DATE($doc_date, '%d/%m/%Y') ... ";
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Re: load data infile

Post by bouncer »

ghurtado wrote:Could you do something like the following?

Code: Select all

$sql = " ... `status_date` = STR_TO_DATE($doc_date, '%d/%m/%Y') ... ";
no that didn't work :(

regards
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Re: load data infile

Post by bouncer »

i've tried this one and now it work just fine ... :D

Code: Select all

 
LOAD DATA INFILE 'example.csv' REPLACE INTO TABLE `content`
                FIELDS TERMINATED BY ';'
                OPTIONALLY ENCLOSED BY ''
                LINES TERMINATED BY '\n'
                (`ref`, @datefield1)
                SET 
                `status_date` = STR_TO_DATE(@datefield1, '%d/%m/%Y'),
                `doc_date` = CURRENT_TIMESTAMP;
 
regards
Post Reply