Store PDF in MySQL database

2020-03-01 01:04发布

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?

4条回答
我想做一个坏孩纸
2楼-- · 2020-03-01 01:19

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.

查看更多
唯我独甜
3楼-- · 2020-03-01 01:22

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.

查看更多
Viruses.
4楼-- · 2020-03-01 01:37

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.

查看更多
地球回转人心会变
5楼-- · 2020-03-01 01:37

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.

查看更多
登录 后发表回答