User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 15 Dec 2004, 11:41   #1
CaShY
Registered User
 
CaShY's Avatar
 
Join Date: Jul 2002
Location: uk
Posts: 50
CaShY is an unknown quantity at this point
mysql and loading (PHP)

Hi i have come accross a little problem that i need some help with

basically i need to load a file into my mysql database and this all works fine using a cvs file and the LOAD feature

which goes like

LOAD DATA LOCAL INFILE $file INTO TABLE `results` FIELDS TERMINATED BY ',' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'(
`userid` , `network` , `profit`
)

however theres a 4th collumn in my table that i want to put data into. I want to put in the date it was added in the 4th feild in my table however this need to be the time(); function in php. Is there anyway to combine the two so that it will also automatically put in the time of the insert.

Thanks
__________________
CaShY
CaShY is offline   Reply With Quote
Unread 15 Dec 2004, 12:13   #2
wu_trax
Registered User
 
Join Date: Jan 2003
Posts: 4,290
wu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet society
Re: mysql and loading (PHP)

you could use fgetcsv, then foreach all the way through the result and create insert-statments.
that will probably be slower than what you do now, but it should work.
i didn't even now what you did there is possible, so thanks for the info, maybe there is another way.
__________________
im not tolerant, i just dont care.
wu_trax is offline   Reply With Quote
Unread 15 Dec 2004, 12:37   #3
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: mysql and loading (PHP)

If the column that you want to have the current time in is of type TIMESTAMP and you don't specify it as one of the fields getting data in your LOAD DATA INFILE then it should be set to the current date/time which sounds similar at least to what you want. If it's any other type then you might be stuck, as far as I was aware default values on columns cannot be evaluated at insertion-time so you can't directly use mySQL functions in them.

Alternatively, you could load all of that data into a temporary table and then propagate your original table iteratively (or if there's some mySQL function for it, I don't know) inserting the current time as part of the query to build the table.
__________________
You're now playing ketchup
pablissimo is offline   Reply With Quote
Unread 16 Dec 2004, 18:38   #4
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Re: mysql and loading (PHP)

Or if you particularly need the result from PHP's time(), you could always insert just the data you have, then use an UPDATE to change all those records time field appropriately.
queball is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 19:13.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018