zend-db

Tablegateway "insert" gets executed but no values are written into table


Environment: Docker container, where PHPand MySQL runs in seperated containers

I have a table "persons" and want to insert values using TableGateway. The code gets executed and I can catch the last inserted value. It's an autoincrement and every performed insert on this table increments this value.

But no values are saved in the table (e.g. phone)

public function __construct(
        ...
        TableGateway $tablePersons,
        ...
    ) {
        ...
        $this->tablePersons = $tablePersons;
        ...
    }

...
$this->tablePersons->insert(['phone' => 123456]);
$id = $this->tablePersons->lastInsertValue;

I printed the sql string out and it looks fine.

$sql = $this->tablePersons->getSql();
$insert = $sql->insert();
$insert->values(['phone' => 123456]);
print $sql->buildSqlString($insert);

// Result: INSERT INTO `persons` (`phone`) VALUES ('123456')

I performed this query on phpmyadmin and everthing looks good, values are stored.

mysql_error.log is empty mysql.log shows the following:

2019-05-12T23:34:20.940510Z    34 Connect   root@172.20.0.5 on app using TCP/IP
2019-05-12T23:34:20.940795Z    34 Query SET AUTOCOMMIT=0
2019-05-12T23:34:20.943878Z    34 Query INSERT INTO `persons` (`phone`) VALUES (42)
2019-05-12T23:34:20.944329Z    34 Quit

To bypass the zend-framework, I went to the index.php and performed a classic mysqli query:

$conn = new mysqli(## same values as in the zend-db adapter config ##);
$sql = "INSERT INTO persons (phone) VALUES (123456)";
$conn->query($sql);

This works perfectly fine - a new row gets stored. So I think, a problem with the environment may be excluded.

I need a hint, an idea why the values are not saved when I run the query with the framework functions.


Solution

  • Try to confirm that you' ve to initiated a database transaction that is preventing AUTO_COMMIT of the inserted values. Also, confirm that the field length for the phone and other fields are large enough to store the values passed.