10 months ago

Getting empty ID after running $model->save()

Posted 10 months ago by slovenianGooner


I'm having a very specific issue occurring on only one server and only one PHP version that I can't get my head around.

I have a basic insert code for inserting a model - set up auto incrementing primary key with a migration, everything as it should be.

After running $model->save() I do some other code as well and the ID written in the model is always 0.

I've tracked it down to the Processor and the processInsertGetId method. It seems the query to return the last inserted ID always returns 0.

This happens on a specific server - same code runs perfectly on my Valet instance and on a dev server I've got set up. I use the same MySQL versions (5.7.22) and the same PHP versions (7.2).

What I think, it has to be an issue with the pdo-mysql hence I updated all to the latest version but I still get no ID.

Apps running PHP 7.1 on the same server return the ID.

Laravel version is 5.7.

I am baffled here and I really need a fix for this - can someone help?

Maybe there is PHP setting I got wrong or something else - but I just can't figure out why. I tried Googling and came up empty.

This is the PDOConnection:

PDOConnection {#518
  inTransaction: false
  attributes: {
    PERSISTENT: false
    DRIVER_NAME: "mysql"
    SERVER_INFO: "Uptime: 621  Threads: 2  Questions: 149716  Slow queries: 0  Opens: 4949  Flush tables: 1  Open tables: 416  Queries per second avg: 241.088"
    CLIENT_VERSION: "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
    SERVER_VERSION: "5.7.24-0ubuntu0.16.04.1"
    STATEMENT_CLASS: array:2 [
      0 => "Doctrine\DBAL\Driver\PDOStatement"
      1 => []
    CONNECTION_STATUS: "Localhost via UNIX socket"

The only difference is to my local server is that there is only one thread, while here it's 2. Could that be something?


Please sign in or create an account to participate in this conversation.