CakePHP cannot save Postgres database, but with successful return

Has anyone encountered this problem before?

In CakePHP, I have it.

$this->loadModel('BankBalance'); $data = array("BankBalance"=> array(bla bla bla...); $this->BankBalance->save($data); $log = $this->BankBalance->getDataSource()->getLog(false, false); debug($log); 

and debugging will return it to me

 array( 'log' => array( (int) 0 => array( 'query' => 'BEGIN', 'params' => array(), 'affected' => null, 'numRows' => null, 'took' => null ), (int) 1 => array( 'query' => 'INSERT INTO bla bla bla...)', 'params' => array(), 'affected' => (int) 1, 'numRows' => (int) 1, 'took' => (float) 7 ), (int) 2 => array( 'query' => 'COMMIT', 'params' => array(), 'affected' => (int) 1, 'numRows' => (int) 1, 'took' => (float) 7 ) ), 'count' => (int) 3, 'time' => (float) 14) 

In fact, the row was not inserted despite the successful message. But if I copied the generated SQL and ran it, it really inserts INSERT into the table. I also tried using saveMany, but did not do INSERTION, but still returned a successful message to me.

CakePHP is missing an error log. updateAll works fine for UPDATE. And now I'm looking for sql INSERT

I can’t even do β†’ save to a simple table with one field (the character changes (50)), no triggers, nothing. Give me a success message, but no physical data is inserted into the table.

+5
source share
1 answer

If you want to insert data, you need to create a new one by placing

 $this->BankBalance->create(); 

somewhere earlier (best at the beginning)

 $this->BankBalance->save($data); 

and put

 if($this->BankBalance->save($data)){ $log = $this->BankBalance->getDataSource()->getLog(false, false); debug($log); } 

instead

 $this->BankBalance->save($data); $log = $this->BankBalance->getDataSource()->getLog(false, false); debug($log); 

to find out if saved successfully

0
source

Source: https://habr.com/ru/post/1264355/


All Articles