DDDBL 2.0
 All Classes Namespaces Files Functions Variables
QueryException.class.php
Go to the documentation of this file.
1 <?php
2 
3 namespace DDDBL;
4 
11 class QueryException extends \Exception {
12 
22  public function __construct(\PDOStatement $objPDO, array $arrQueryDefinition) {
23 
24  $strMessage = self::createErrorMessage($objPDO, $arrQueryDefinition);
25 
26  parent::__construct($strMessage);
27 
28  }
29 
41  private function createErrorMessage(\PDOStatement $objPDO, array $arrQueryDefinition) {
42 
43  $strMessage = self::flattenQueryErrorInfo($objPDO);
44  $strMessage .= self::flattenQueryDefiniton($arrQueryDefinition);
45 
46  return $strMessage;
47 
48  }
49 
60  private function flattenQueryErrorInfo(\PDOStatement $objPDO) {
61 
62  $arrErrorInfo = $objPDO->errorInfo();
63 
64  $strMessage = '';
65 
66  if(!empty($arrErrorInfo) && !empty($arrErrorInfo[0]) && '00000' !== $arrErrorInfo[0])
67  $strMessage = "\nError-Code: {$arrErrorInfo[0]}\nError-Message: {$arrErrorInfo[2]}\n";
68 
69  return $strMessage;
70 
71  }
72 
84  private function flattenQueryDefiniton(array $arrQueryDefinition) {
85 
86  $strMessage = "\nQuery-Definiton:\n";
87 
88  foreach($arrQueryDefinition AS $strKeyword => $strContent)
89  if(is_scalar($strContent))
90  $strMessage .= "$strKeyword: $strContent\n";
91 
92  return $strMessage . "\n";
93 
94  }
95 
96 }