0

I am returning a short array via:

return $stmt->fetchAll( PDO::FETCH_ASSOC );

and running into a very strange issue. In my test case, I have three rows of data. Each row has a unique ID, a processed flag, and a content varchar:

`incomingstring` VARCHAR(5000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NULL DEFAULT NULL;

This varchar contains a multiline string, delimited by CRLF terminated with message suffix:

define( "MESSAGE_SUFFIX", '\x7c\x1c\x0d' );

I parse this string for message parts. The problem is that not everything is returning as expected. The first row returns fine. The second and third row return, but only part (the last part) of the message returns. I know the data is there, I can see it if I look into the database directly, but what comes into the array does not contain the whole varchar.

My best guess is that the termination character is messing up the associative array in some way? Maybe? Any suggestions for a fix? I can't tear the control characters out of the DB record itself because I need them there for other processes, this parser needs to be able to read the data without altering it.

Using MySQL 8.0.11 and PHP 7.2.7

Thanks!

Gerdofal
  • 91
  • 7
  • Just prepare minimal reproduce test - two scripts, one for create test schema and fill with test data, and second - with fetch and var_dump. And post it. – Dmitry MiksIr Jun 09 '20 at 20:42
  • 1
    Should the define value not be in double quotes to be interpolated? – Markus Zeller Jun 09 '20 at 20:44
  • @MarkusZeller in this case it is used in preg_match. – Gerdofal Jun 09 '20 at 22:50
  • 2
    Do you some type of escaping before writing into the database? It seem you use PDO. Can you please provide one select and one update/insert by updating your question? – Markus Zeller Jun 10 '20 at 07:48
  • You need to give us [mcve]. We do not have enough details to reproduce the same scenario on our computers. Please share the code and the data. – Dharman Jun 10 '20 at 11:21
  • 1
    @MarkusZeller Thanks, I found the answer while looking into the type escaping. There was indeed an issue with the control characters, but the issue was in one of the two inserts for the table (which is why some of it worked and some didn't). Both inserts were escaping properly, but one was going a step further and trimming out characters which should have been left. It wasn't obvious at first because some of the control characters being trimmed were messing up the console display I was using to debug (overwriting lines that should have been there). Became obvious when dumping to file. – Gerdofal Jun 11 '20 at 00:08

0 Answers0