DBALException bin2hex() expects parameter 1 to be string, resource given #5794

Open
opened 2026-01-22 15:18:08 +01:00 by admin · 0 comments
Owner

Originally created by @holantomas on GitHub (Dec 5, 2017).

Originally assigned to: @Ocramius on GitHub.

Hi,
I have entity FileContent with few properities id,bytes. bytes is blob. When I'm saving file stream from upload to DB it try to throw exeption bellow but it fall on param formating when it try to call bin2hex on stream resource (uploaded file).

Trying to throw exception
SQLSTATE[08S01]: Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes"

File: .../doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:197

187:         *
188:         * @return string
189:         */
190:        private static function formatParameters(array $params)
191:        {
192:            return '[' . implode(', ', array_map(function ($param) {
193:                $json = @json_encode($param);
194:    
195:                if (! is_string($json) || $json == 'null' && is_string($param)) {
196:                    // JSON encoding failed, this is not a UTF-8 string.
197: // THIS LINE -->   return '"\x' . implode('\x', str_split(bin2hex($param), 2)) . '"';
198:                }
199:    
200:                return $json;
201:            }, $params)) . ']';

Don't know what else to report, so you can ask what you need.
And yes I know how to solve first exception.

Originally created by @holantomas on GitHub (Dec 5, 2017). Originally assigned to: @Ocramius on GitHub. Hi, I have entity `FileContent` with few properities `id`,`bytes`. `bytes` is `blob`. When I'm saving file stream from upload to DB it try to throw exeption bellow but it fall on param formating when it try to call bin2hex on stream resource (uploaded file). Trying to throw exception `SQLSTATE[08S01]: Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes"` ``` File: .../doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:197 187: * 188: * @return string 189: */ 190: private static function formatParameters(array $params) 191: { 192: return '[' . implode(', ', array_map(function ($param) { 193: $json = @json_encode($param); 194: 195: if (! is_string($json) || $json == 'null' && is_string($param)) { 196: // JSON encoding failed, this is not a UTF-8 string. 197: // THIS LINE --> return '"\x' . implode('\x', str_split(bin2hex($param), 2)) . '"'; 198: } 199: 200: return $json; 201: }, $params)) . ']'; ``` Don't know what else to report, so you can ask what you need. And yes I know how to solve first exception.
admin added the BugDuplicate labels 2026-01-22 15:18:08 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5794