Page 1 of 1
Daily read a csv file and insert it into a MSSQL Server
Posted: Thu Feb 14, 2008 9:29 pm
by Zero20two
I have log files that are generated daily. They are named something like: 448701b8-a234-fwersd-23f23dsd_20080214.csv. The first part of the name is always the same but the last part is that days date. How can I daily open the new file, insert it into a MSSQL server and move the file to a folder? I know how to connect to SQL I am just a little shady on the rest.
Thanks!
Re: Daily read a csv file and insert it into a MSSQL Server
Posted: Thu Feb 14, 2008 10:09 pm
by Christopher
I am assuming you want a PHP script to do this. To generate the date you would use date('Ymd');, the use file_get_contents() to load the file and the mssql_*() functions or PDO to write it to the database.
Re: Daily read a csv file and insert it into a MSSQL Server
Posted: Thu Feb 14, 2008 10:16 pm
by Zero20two
I'm not sure I explained it right. I need to open the existing file and grab the contents and send to mssql. How do I ignore the string of letters and numbers before the date in the filename and open todays file? Thanks again!
Re: Daily read a csv file and insert it into a MSSQL Server
Posted: Thu Feb 14, 2008 10:19 pm
by Christopher
No, you explained it right. You just didn't read carefully.
Code: Select all
$filename = '448701b8-a234-fwersd-23f23dsd_' . date('Ymd') . '.csv';
Re: Daily read a csv file and insert it into a MSSQL Server
Posted: Fri Feb 15, 2008 3:00 pm
by Zero20two
Can you tell me what is wrong with this?
$filename = "//iar-dc5/logs/'448701b8-a239-4db6-a1e2-47b9147d93dd_'.date('Ymd')'.csv'";
If I change it to - $filename = "//iar-dc5/logs/448701b8-a239-4db6-a1e2-47b9147d93dd_20080213.csv";
it works fine. Thanks!