S
S
Shillkas112019-01-29 18:00:03
PHP
Shillkas11, 2019-01-29 18:00:03

Why is PHP PDO converting text to binary?

I am using PHP PDO:

$statement = $connection->prepare("UPDATE item SET description = :desc WHERE id = :item_id");
$statement->execute([':desc' => 'Текст на русском и английском с элементами html большой длины (mediumText)', ':item_id' => 26]);

When executing this request, an error occurs:
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\x81<sup>...' for column 'description' at row 3
. In the request logs, I found that for some reason the data is already being transmitted in this form: {":item_id":26, ":desc":"(binary value)"}, i.e. it is not clear why the description becomes a binary value, which is why an error occurs when executing the request, because in a db the field has data type MediumText, and cannot accept binary. How can this be fixed?
PS When inserting data directly into the database, without PDO, everything works.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2016-06-13
@dev400

SELECT cat1.id, cat1.cat_name, cat1.cat_url, cat1.parent, cat2.name as parent_name  
FROM `categories` AS cat1 
LEFT JOIN `categories` AS cat2 ON cat2.id = cat1.patent
WHERE cat1.`cat_url` = <значение>

D
DarkMatter, 2016-06-13
@darkmatter

You need something like:

SELECT * FROM `categories`
WHERE
IF (`cat_url` > 0, SELECT * FROM `table` )
GROUP BY...

But take a closer look at performance...

F
FanatPHP, 2019-01-29
@Shillkas11

No "conversion" to "binary" occurs when the query is executed .
In error messages/logs, non-standard characters are encoded for greater compatibility. This format has nothing to do with the executed request .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question