PHP insert to CSV
- Started
- Last post
- 8 Responses
- seed
Is it possible to insert data directly into a CSV file? Using it as sort of a database. I didn't find anything on it but I thought it would be worth a try. Otherwise user action would be required to convert the db data as a CSV wouldn't it?
- maximillion_0
you can insert the data into a csv file using php's file functions but it might be difficult to find the insertion point, it would be much easier to do all the insert/updates into your db and then export a cvs file via php.
this might help
http://www.webmasterworld.com/fo…
- seed0
I am basically trying to do the same thing the person in the thread is doing. Generating a CSV file and FTPing it automatically. Concatenating an existing file using a '$nextline' variable as mentioned in the last post seems unlikely. As you mentioned I don't know what that variable would have as a reference of where to start the next line.
I could use an export link to generate the CSV but I would like it to not require user action if the rest of the process (ftp) is automatic.
- seed0
When the user submits the form and the record is added to the database it could insert and then create the CSV. Is it possible to create the CSV and store it in a folder on the server and opposed to exporting it to the clients desktop?
- Nairn0
CSV is fundamentally just a text file, so you can certainly 'add' to it, but as maxi_ says, it would be hard to insert 'in' to it.
I guess it depends on how big your csv file will ultimately be and how neat you'd like your database to be structured.
- maximillion_0
you could write the csv fiel as you want, easier than setting up a cron job if it is following a form submission. check the thread (or search) webmasterworld link i posted earlier as how to export from mysql to csv. think about yr data management tho, if everytime a new file is created the older ones are redudant then you want to remove them from the server...good housekeeping
- seed0
Anyone know the answer to this specifically?
'Is it possible to create the CSV (from the database) and store it in a folder on the server and opposed to exporting it to the clients desktop?'
- neverblink0
sure, you will need a php file that reads out your database, creates a textfile and writes the contents into it.. you could offer that textfile as a download-link to the client or force a download with some nifty header-works
- seed0
Im hoping to create it and save it in a folder on the serve as opposed to letting the client download it.