I am developing an application and I need to create invoices in PDF. I'm using pdfbundle and PDF files are created correctly:
public function helloAction()
{
$format = $this->get('request')->get('_format');
$name = "work!!!";
return $this->render(sprintf('miomioBundle:Venta:helloAction.%s.twig', $format), array('name' => $name));
}
But how could I store that file in the database?
You'd be far better off storing them on disk as files and reference their location in your DB. So store:
/path/to/store/invoice_434992.pdf
in a relevant table, each with a unique filename and reference it where you need to.
Is there any particular requirement you want to store those pdfs in the database. Generally its a bad idea to store large binary content in the database.
Let the invoices be in files, with a unique filename, and store the just the path to file in the database table.
I've done this. There is avery good article on how to do it.
http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx
As others have said, it may not be a good idea to store binary data in a database.
You could create a table in your database that is:
____________________________________________
| ID | TIME | QUERY | PDF_NAME | PDF_FILE |
|----|------|-------|----------|-----------|
...
The type of the PDF_FILE would be BLOB, and the rest are self-explanatory. This way, if you wanted, you could search for the result of a query that happened a while back.