lastError() 공개 메소드

Returns a formatted error message from previous database operation.
public lastError ( PDOStatement $query = null ) : string
$query PDOStatement the query to extract the error from if any
리턴 string Error message with error number
 /**
  * testLastError
  *
  * @return void
  * @access public
  */
 function testLastError()
 {
     $debug = Configure::read('debug');
     Configure::write('debug', 0);
     $this->db->simulate = false;
     $query = 'SELECT [name] FROM [categories]';
     $this->assertTrue($this->db->execute($query) !== false);
     $this->assertNull($this->db->lastError());
     $query = 'SELECT [inexistent_field] FROM [categories]';
     $this->assertFalse($this->db->execute($query));
     $this->assertNotNull($this->db->lastError());
     $query = 'SELECT [name] FROM [categories]';
     $this->assertTrue($this->db->execute($query) !== false);
     $this->assertNull($this->db->lastError());
     Configure::write('debug', $debug);
 }