php - Save random_bytes-generated key in database using Doctrine
Get the solution ↓↓↓I am trying to generate a relatively secure key and store it in the database. I am using PHP Symfony and Doctrine to manage my MySQL-Database. Here is my code:
$account->setVk(random_bytes(32));
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($account);
$entityManager->flush();
I always get the following error:
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xB7\xC3!\xEC\xE0\xCD...'
Just using a normal String like '12345' works well. Vk is a column of type String with the length of 255. Why is the String weirdly formatted like that and why wont Doctrine not accept the String generated by random_bytes? (Although I think the error is more on the MySQL side of things)
Answer
Solution:
You are triying to save a random string (random_bytes) in a property defined in database as DateTime type.
Go to account entity and check the $vk property. You should change ORM/Column to strig if you really need to save a random string.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: ftp_put(): can't open that file: no such file or directory
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.