DDC-3189: blob doctrine2 not inserting file in mysql #3952

Open
opened 2026-01-22 14:32:16 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 24, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user gustavomr:

I have an entity mapped as:

/****
 * @Entity @Table(name="Upload")
****/
class Upload
{
/*** @Id @Column(type="integer") @GeneratedValue ***/
protected $id;

/*** @Column(type="string") ***/
protected $nome;

/*** @Column(type="blob") ***/
protected $arquivo;

When I use this (WORKS)

 $query = "INSERT INTO Upload1 (name, size, type, content ) "."VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

 mysql_query($query)

When I use this doctrine way (NOT WORKING, if you try to get this file from mysql, return a corrupted or empty file)

$upload = new Upload();

$upload-> setContent($content);
$upload-> setName($fileName);
$upload-> setSize($fileSize);
$upload-> setType($fileType);

$entityManager->persist($upload);
$entityManager->flush();

My html file:

<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr> 
<td width="246"> 
<input type="hidden" name="MAX*FILE*SIZE" value="2000000">
<input name="userfile" type="file" id="userfile"> 
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload    "></td>
</tr>
</table>
</form>
Originally created by @doctrinebot on GitHub (Jun 24, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user gustavomr: I have an entity mapped as: ``` /**** * @Entity @Table(name="Upload") ****/ class Upload { /*** @Id @Column(type="integer") @GeneratedValue ***/ protected $id; /*** @Column(type="string") ***/ protected $nome; /*** @Column(type="blob") ***/ protected $arquivo; ``` When I use this (WORKS) ``` $query = "INSERT INTO Upload1 (name, size, type, content ) "."VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) ``` When I use this doctrine way (NOT WORKING, if you try to get this file from mysql, return a corrupted or empty file) ``` $upload = new Upload(); $upload-> setContent($content); $upload-> setName($fileName); $upload-> setSize($fileSize); $upload-> setType($fileType); $entityManager->persist($upload); $entityManager->flush(); ``` My html file: ``` <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX*FILE*SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> ```
admin added the Bug label 2026-01-22 14:32:16 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 24, 2014):

Comment created by gustavomr:

trying to insert this image

@doctrinebot commented on GitHub (Jun 24, 2014): Comment created by gustavomr: trying to insert this image
Author
Owner

@doctrinebot commented on GitHub (Jun 24, 2014):

Comment created by gustavomr:

Using:
$entityManager->getConnection()->getConfiguration()->setSQLLogger( new Doctrine\DBAL\Logging\EchoSQLLogger());

Getting:
"START TRANSACTION" INSERT INTO Upload (name, type, size, content) VALUES (?, ?, ?, ?) array(4) { [1] => string(5) "a.png" [2] => string(9) "image/png" [3] => int(264547) [4] => string(270342) "‰PNG  \0\0\0 IHDR\0\0@\0\0„\0\0\0v/jõ\0\0\0sBITÛáOà\0\0\0tEXtSoftware\0gnome-screenshotï¿>\0\0 \0IDATxœìw](TÅöÀÏܲ{·$›I¥“Лҫ€ QPô©`{êÏγ÷ŸýYÀ‚ˆ"¢ô %½m’í햙ߛ,›mÙe¾>š½÷Ι™3gæÎœ;)3ÿR P( …B¡P( …\0\0³X¾Ÿ†X]ŸÞ]ÿÂôP(\0àÜnñ¯N…B¡P( …B¡P(„B\0\0.÷ñ’ÊüünÝºÇøîÚl¶m;æçfh4\0@BUR)”3®©šR( …B¡P( …ræa2Y«ëV\0@4……}Y–<¸§×KEÙ±ãHaaßâ¢#n·\0Ãf¦§ÄÇÇþÅé¦PÎ0¨‹B¡P( …B¡P(g(„ÙttTJ5"\0< g§æefe¥ú?3rd¿Š £V.W7ì&\0˜âF‰ø%9uÆF\0HINø«pôx…ZÅuÉL¥“Ô(‘Ù³¯\0ú÷í}ã¶9°A‡Óãr¥Åé¯n"... } array(4) { [1] => string(6) "string" [2] => string(6) "string" [3] => string(7) "integer" [4] => string(4) "blob" } "COMMIT"

@doctrinebot commented on GitHub (Jun 24, 2014): Comment created by gustavomr: Using: $entityManager->getConnection()->getConfiguration()->setSQLLogger( new Doctrine\DBAL\Logging\EchoSQLLogger()); Getting: "START TRANSACTION" INSERT INTO Upload (name, type, size, content) VALUES (?, ?, ?, ?) array(4) { [1] => string(5) "a.png" [2] => string(9) "image/png" [3] => int(264547) [4] => string(270342) "‰PNG  \0\0\0 IHDR\0\0@\0\0„\0\0\0v/jõ\0\0\0sBITÛáOà\0\0\0tEXtSoftware\0gnome-screenshotï¿>\0\0 \0IDATxœìw](TÅöÀÏܲ{·$›<sup>I¥“Лҫ€ QPô©`{êÏγ÷</sup>ŸýYÀ‚ˆ\"¢ô %½m’í햙ߛ,›mÙe¾>š½÷Ι™3gæÎœ;)3ÿR P( …B¡P( …\0\0³X¾Ÿ†X]ŸÞ]ÿÂôP(\0àÜnñ¯N…B¡P( …B¡P(„B\0\0\.÷ñ’ÊüünÝºÇøîÚl¶m;æçfh4\0@BUR)”3®©šR( …B¡P( …ræa2Y<ins>«ëV\0@4……}Y–<¸§×KEÙ±ãHaaßâ¢#n·\0Ãf¦§ÄÇÇþÅé¦PÎ0¨‹B¡P( …B¡P(g(„ÙttTJ5\"\0< g§æefe¥ú?3rd¿Š £V.W7ì&\0˜âF</ins>‰ø%9uÆF\0HINø«pôx…ZÅuÉL¥“Ô(‘Ù³¯\0ú÷í}ã¶9°A‡Óãr¥Åé¯n"... } array(4) { [1] => string(6) "string" [2] => string(6) "string" [3] => string(7) "integer" [4] => string(4) "blob" } "COMMIT"
Author
Owner

@doctrinebot commented on GitHub (Jun 26, 2014):

Comment created by @deeky666:

This looks more like a DBAL issue. Can you please provide the error/exception message that you receive from the driver/database server? Also do you use PDOMySQL or mysqli driver?

@doctrinebot commented on GitHub (Jun 26, 2014): Comment created by @deeky666: This looks more like a DBAL issue. Can you please provide the error/exception message that you receive from the driver/database server? Also do you use PDOMySQL or mysqli driver?
Author
Owner

@doctrinebot commented on GitHub (Jun 26, 2014):

Comment created by gustavomr:

Steve,

I'm not getting any error/expection. Table looks like insert the blob file but when I try to download it is corrupted. You could see at getting .zip file and executing it.

I'm using PDOMysql.

@doctrinebot commented on GitHub (Jun 26, 2014): Comment created by gustavomr: Steve, I'm not getting any error/expection. Table looks like insert the blob file but when I try to download it is corrupted. You could see at getting .zip file and executing it. I'm using PDOMysql.
Author
Owner

@doctrinebot commented on GitHub (Jun 26, 2014):

Comment created by @ocramius:

This would probably need a data sample to reproduce the issue.

@doctrinebot commented on GitHub (Jun 26, 2014): Comment created by @ocramius: This would probably need a data sample to reproduce the issue.
Author
Owner

@doctrinebot commented on GitHub (Jun 26, 2014):

Comment created by gustavomr:

Marco,

you could use project attached and image in order to reproduce.

@doctrinebot commented on GitHub (Jun 26, 2014): Comment created by gustavomr: Marco, you could use project attached and image in order to reproduce.
Author
Owner

@doctrinebot commented on GitHub (Jun 26, 2014):

Comment created by @ocramius:

[~gustavomr] you should actually provide a functional test for this in case, see https://github.com/doctrine/dbal/tree/master/tests/Doctrine/Tests/DBAL

For example, the zip file you uploaded fails on various includes, and doesn't show the failures to me.

@doctrinebot commented on GitHub (Jun 26, 2014): Comment created by @ocramius: [~gustavomr] you should actually provide a functional test for this in case, see https://github.com/doctrine/dbal/tree/master/tests/Doctrine/Tests/DBAL For example, the zip file you uploaded fails on various includes, and doesn't show the failures to me.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3952