Conditions | 5 |
Paths | 10 |
Total Lines | 25 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 0 |
1 | <?php |
||
17 | public static function fromSqlSrvErrors() |
||
18 | { |
||
19 | $message = ''; |
||
20 | $sqlState = null; |
||
21 | $errorCode = null; |
||
22 | |||
23 | foreach ((array) sqlsrv_errors(SQLSRV_ERR_ERRORS) as $error) { |
||
24 | $message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n"; |
||
25 | |||
26 | if ($sqlState === null) { |
||
27 | $sqlState = $error['SQLSTATE']; |
||
28 | } |
||
29 | |||
30 | if ($errorCode !== null) { |
||
31 | continue; |
||
32 | } |
||
33 | |||
34 | $errorCode = $error['code']; |
||
35 | } |
||
36 | |||
37 | if (! $message) { |
||
38 | $message = 'SQL Server error occurred but no error message was retrieved from driver.'; |
||
39 | } |
||
40 | |||
41 | return new self(rtrim($message), $sqlState, $errorCode); |
||
42 | } |
||
44 |