0
public function save($itemId, $invoiceName)
{
    $query = "
           INSERT INTO invoice (item_id, invoice_name)
           VALUES (" . $itemId . ",'" . $invoiceName . ")
    ";
    $connection = $this->entityManager->getConnection('master');
    return $connection->executeQuery($query);
}

Error while trying to insert into table:

An exception occurred while executing ' INSERT INTO invoice (item_id, invoice_name) VALUES (10600029,'FV/1823/06/2018/SOL') ': SQLSTATE[HY000]: General error: 1290 The MySQL server is running with the --read-only option so it cannot execute this statement

Checked connection to DB its fine. Tried to save something with same user with a DBeaver DB client and it went through all fine - saved without any problem.

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
Ydrus
  • 11
  • 6

2 Answers2

0

you need to close the connection used before to change connection and insert I think, try something like this:

$connection = $this->entityManager->getConnection()->close();

$query = "
       INSERT INTO invoice (item_id, invoice_name)
       VALUES (" . $itemId . ",'" . $invoiceName . ")
";
$connection = $this->entityManager->getConnection('master');
return $connection->executeQuery($query);
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
0

Even tho I specified 'master' the request was catched by slave all the time.

$entityManager->getConnection()->prepare('INSERT ... ')->execute();

Appeared to fix the problem.

Ydrus
  • 11
  • 6