88use Foolz \SphinxQL \Exception \ConnectionException ;
99use Foolz \SphinxQL \Exception \DatabaseException ;
1010use Foolz \SphinxQL \Exception \SphinxQLException ;
11+ use mysqli_sql_exception ;
1112
1213/**
1314 * SphinxQL connection class utilizing the MySQLi extension.
@@ -51,6 +52,12 @@ public function connect()
5152 if (!$ conn ->real_connect ($ data ['host ' ], null , null , null , (int ) $ data ['port ' ], $ data ['socket ' ])) {
5253 throw new ConnectionException ('Connection Error: [ ' .$ conn ->connect_errno .'] ' .$ conn ->connect_error );
5354 }
55+ } catch (mysqli_sql_exception $ exception ) {
56+ throw new ConnectionException (
57+ 'Connection Error: [ ' .$ exception ->getCode ().'] ' .$ exception ->getMessage (),
58+ (int ) $ exception ->getCode (),
59+ $ exception
60+ );
5461 } finally {
5562 restore_error_handler ();
5663 }
@@ -102,6 +109,12 @@ public function query($query)
102109 * ERROR mysqli::prepare(): (08S01/1047): unknown command (code=22) - prepare() not implemented by Sphinx/Manticore
103110 */
104111 $ resource = @$ this ->getConnection ()->query ($ query );
112+ } catch (mysqli_sql_exception $ exception ) {
113+ throw new DatabaseException (
114+ '[ ' .$ exception ->getCode ().'] ' .$ exception ->getMessage ().' [ ' .$ query .'] ' ,
115+ (int ) $ exception ->getCode (),
116+ $ exception
117+ );
105118 } finally {
106119 restore_error_handler ();
107120 }
@@ -127,7 +140,15 @@ public function multiQuery(array $queue)
127140
128141 $ this ->ensureConnection ();
129142
130- $ this ->getConnection ()->multi_query (implode ('; ' , $ queue ));
143+ try {
144+ $ this ->getConnection ()->multi_query (implode ('; ' , $ queue ));
145+ } catch (mysqli_sql_exception $ exception ) {
146+ throw new DatabaseException (
147+ '[ ' .$ exception ->getCode ().'] ' .$ exception ->getMessage ().' [ ' .implode ('; ' , $ queue ).'] ' ,
148+ (int ) $ exception ->getCode (),
149+ $ exception
150+ );
151+ }
131152
132153 if ($ this ->getConnection ()->error ) {
133154 throw new DatabaseException ('[ ' .$ this ->getConnection ()->errno .'] ' .
@@ -146,7 +167,13 @@ public function escape($value)
146167 {
147168 $ this ->ensureConnection ();
148169
149- if (($ value = $ this ->getConnection ()->real_escape_string ((string ) $ value )) === false ) {
170+ try {
171+ $ value = $ this ->getConnection ()->real_escape_string ((string ) $ value );
172+ } catch (mysqli_sql_exception $ exception ) {
173+ throw new DatabaseException ($ exception ->getMessage (), (int ) $ exception ->getCode (), $ exception );
174+ }
175+
176+ if ($ value === false ) {
150177 // @codeCoverageIgnoreStart
151178 throw new DatabaseException ($ this ->getConnection ()->error , $ this ->getConnection ()->errno );
152179 // @codeCoverageIgnoreEnd
0 commit comments