@@ -103,7 +103,10 @@ public function __construct($params)
103
103
/**
104
104
* Connect to the database.
105
105
*
106
- * @param boolean $persistent
106
+ * @param boolean $persistent
107
+ *
108
+ * @throws DatabaseException
109
+ *
107
110
* @return mixed
108
111
*/
109
112
public function connect (bool $ persistent = false )
@@ -114,9 +117,9 @@ public function connect(bool $persistent = false)
114
117
'UID ' => empty ($ this ->username ) ? '' : $ this ->username ,
115
118
'PWD ' => empty ($ this ->password ) ? '' : $ this ->password ,
116
119
'Database ' => $ this ->database ,
117
- 'ConnectionPooling ' => ( $ persistent === true ) ? 1 : 0 ,
120
+ 'ConnectionPooling ' => $ persistent ? 1 : 0 ,
118
121
'CharacterSet ' => $ charset ,
119
- 'Encrypt ' => ( $ this ->encrypt === true ) ? 1 : 0 ,
122
+ 'Encrypt ' => $ this ->encrypt === true ? 1 : 0 ,
120
123
'ReturnDatesAsStrings ' => 1 ,
121
124
];
122
125
@@ -127,9 +130,10 @@ public function connect(bool $persistent = false)
127
130
unset($ connection ['UID ' ], $ connection ['PWD ' ]);
128
131
}
129
132
130
- if (false !== ($ this ->connID = sqlsrv_connect ($ this ->hostname , $ connection )))
133
+ $ this ->connID = sqlsrv_connect ($ this ->hostname , $ connection );
134
+
135
+ if ($ this ->connID !== false )
131
136
{
132
- /* Disable warnings as errors behavior. */
133
137
sqlsrv_configure ('WarningsReturnAsErrors ' , 0 );
134
138
135
139
// Determine how identifiers are escaped
@@ -138,9 +142,18 @@ public function connect(bool $persistent = false)
138
142
139
143
$ this ->_quoted_identifier = empty ($ query ) ? false : (bool ) $ query [0 ]->qi ;
140
144
$ this ->escapeChar = ($ this ->_quoted_identifier ) ? '" ' : ['[ ' , '] ' ];
145
+
146
+ return $ this ->connID ;
147
+ }
148
+
149
+ $ errors = [];
150
+
151
+ foreach (sqlsrv_errors (SQLSRV_ERR_ERRORS ) as $ error )
152
+ {
153
+ $ errors [] = preg_replace ('/(\[.+\]\[.+\](?:\[.+\])?)(.+)/ ' , '$2 ' , $ error ['message ' ]);
141
154
}
142
155
143
- return $ this -> connID ;
156
+ throw new DatabaseException ( implode ( "\n" , $ errors )) ;
144
157
}
145
158
146
159
/**
0 commit comments