1
votes

When I have Configure::write('debug', 2); set, a SQL error in Cake outputs the full SQL statement with the error message, like this:

Database Error Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near ','.
SQL Query: SELECT ,
Notice: If you want to customize this error message, create app\View\Errors\pdo_error.ctp

However when I look at the error in the default error.log file created because of the setting Configure::write('log', true);, I get this:

2012-03-07 15:57:53 Error: [PDOException] SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0]
[SQL Server]Incorrect syntax near ','.
0 C:\wamp\www\lib\Cake\Model\Datasource\DboSource.php(436): PDOStatement->execute(Array)

How can I make CakePHP 2.0 save the full SQL Statement when a database error occurs? I'm using this logging in production, so I can't just save the SQL manually or leave debug 2 on.

1

1 Answers

2
votes
// In a view
echo $this->element('sql_dump');

// Elsewhere
$log = $this->Model->getDataSource()->getLog(false, false);