How to export database using kirby (CSV, excel, and SQL)

Good day!

I am now using kirby for a project with a custom widget panel that reads user details and displaying them to a table. The widget panel should also allow users to export the data through csv, excel and sql format. Is there a plugin or anything from kirby that can export database files?

I don’t know of a plugin, but Kirby’s toolkit provides the Database class that facilitates database handling.

https://getkirby.com/docs/cookbook/database
https://getkirby.com/docs/developer-guide/toolkit/database

Don’t know about database files.

As regards Excel or CSV, there are PHP libraries you can use.

1 Like

Thanks for the response! I already read those and use it on integrating mysql on my kirby project. My problem was on downloading / exporting the database on different filetypes(csv,xlx,sql) just trying my luck if there is something from kirby that can help me simplify things.

Thank you! It will be a big help.

Maybe this is also helpful: https://stackoverflow.com/questions/6750531/using-a-php-file-to-generate-a-mysql-dump

1 Like

Thank you for all the help! I’m almost there now!

I can generate the CSV file when the user clicks the ‘export’ button, but I don’t know how to force the browser to download it. Ideally, I’d like to not even generate the file - just send it directly to the browser, and let it download it to a file in the user’s computer. I tried just sending the data, and it ended up as raw text in a new browser tab…

Any pointers would be a great help…

Found this: https://www.perpetual-beta.org/weblog/php-stream-file-direct.html, don’t know if it helps.

1 Like

Isn’t that where header::download(); from the toolkit is for?

1 Like

you could try download attribute of a element.

https://www.w3schools.com/TAGS/att_a_download.asp

2 Likes

Thank you for all your help guys! Finally got the sql one using mysqldump. As for the CSV one, it was got out of the plan since the sql format is what needed the most. Thanks for all your help!