Question

I'm pretty new to Doctrine, but until now everything went well. I'm able to successfully fetch entities, as well as updating them using

$user = $em->find('User', 1);
$user->setFirstName('This');
$user->setLastName('Works');
$em->flush();

If I execute this code, and take a look into my database, the first name and the last name of the user are updated in fact. However, when I use

$user = new User();
$user->setFirstName('This');
$user->setLastName('Doesnotwork');
$em->persist($user);
$em->flush();

and I take a look in the database, no new records can be found.

So, what is going on here? I know that this is a rather general description, but I don't know where to start debugging... If I call

$em->getUnitOfWork()->getScheduledEntityInsertions()

then the user entity is present and seems to be scheduled for insertion. So, I have absolutely no clue what could be the problem. Anyone? Any help would be greatly appreciated!

EDIT: I continued to debug, and added an EchoSQLLogger to my EntityManagers configuration, however, the EchoSQLLogger never logs anything, even with the working updates of my user. What the heck is going on here?

EDIT2: It turned out that my EntityManager configuration was a total mess. I'm now able to successfully get logs from the EchoSQLLogger, which shows that an INSERT INTO query will be performed, however, still no insertions in my database. It should be noted that I passed an existing PDO object as Connection, and I'm starting to think that something goes wrong with PDO's commit method. However, if I ask PDO for an error code, it returns 0000, meaning no errors, so the rows should be inserted...

Was it helpful?

Solution

I found out what was the problem. It turned out that some properties had default values in MySQL, but were null in PHP. I thought this would be no problem, however it turned out te be a problem. Anyway, problem solved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top