Skip to content

Instantly share code, notes, and snippets.

@IlanFrumer
Created December 10, 2013 10:51
Show Gist options
  • Save IlanFrumer/7888809 to your computer and use it in GitHub Desktop.
Save IlanFrumer/7888809 to your computer and use it in GitHub Desktop.
extracts PDOException error code & message from error message
<?php
preg_match('/^SQLSTATE\[\w+\]:[^:]+:\s*(\d*)\s*(.*)/', $error->getMessage(), $matches) ||
preg_match('/^SQLSTATE\[\w+\]\s*\[(\d+)\]\s*(.*)/', $error->getMessage(), $matches);
$code = $matches[1] ?: "0" ;
$message = $matches[2];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment