Daily read a csv file and insert it into a MSSQL Server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zero20two
Forum Newbie
Posts: 9
Joined: Wed Feb 13, 2008 11:51 am

Daily read a csv file and insert it into a MSSQL Server

Post 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!
User avatar
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

Post 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.
(#10850)
Zero20two
Forum Newbie
Posts: 9
Joined: Wed Feb 13, 2008 11:51 am

Re: Daily read a csv file and insert it into a MSSQL Server

Post 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!
User avatar
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

Post by Christopher »

No, you explained it right. You just didn't read carefully.

Code: Select all

$filename = '448701b8-a234-fwersd-23f23dsd_' . date('Ymd') . '.csv';
(#10850)
Zero20two
Forum Newbie
Posts: 9
Joined: Wed Feb 13, 2008 11:51 am

Re: Daily read a csv file and insert it into a MSSQL Server

Post 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!
Post Reply