-1

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.

hmartini
  • 139
  • 1
  • 6

1 Answers1

1

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.

  • I haven't initiated a transaction. But when I do it and execute the commit() function, then the dataset gets stored. But you did put me on the right track with your hint. Finally an error in the adapter configuration caused the value AUTOCOMMIT to be set to 0. When overwriting the global config with the local config, there was one level in the configurations array too few. Unfortunately, this did not cause an error, but only affected the execution of the queries. – hmartini May 16 '19 at 14:41