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!
Daily read a csv file and insert it into a MSSQL Server
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Daily read a csv file and insert it into a MSSQL Server
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.
(#10850)
Re: Daily read a csv file and insert it into a MSSQL Server
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!
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Daily read a csv file and insert it into a MSSQL Server
No, you explained it right. You just didn't read carefully.
Code: Select all
$filename = '448701b8-a234-fwersd-23f23dsd_' . date('Ymd') . '.csv';(#10850)
Re: Daily read a csv file and insert it into a MSSQL Server
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!
$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!