Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
b7ee1fbc
Unverified
Commit
b7ee1fbc
authored
Jun 23, 2020
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rework deprecated MySQLi exceptions
parent
a7374a24
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
160 additions
and
16 deletions
+160
-16
ConnectionError.php
...Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionError.php
+21
-0
ConnectionFailed.php
...octrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php
+21
-0
FailedReadingStreamOffset.php
...BAL/Driver/Mysqli/Exception/FailedReadingStreamOffset.php
+22
-0
InvalidOption.php
lib/Doctrine/DBAL/Driver/Mysqli/Exception/InvalidOption.php
+28
-0
StatementError.php
lib/Doctrine/DBAL/Driver/Mysqli/Exception/StatementError.php
+21
-0
UnknownType.php
lib/Doctrine/DBAL/Driver/Mysqli/Exception/UnknownType.php
+25
-0
MysqliConnection.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
+6
-5
MysqliStatement.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
+15
-11
phpcs.xml.dist
phpcs.xml.dist
+1
-0
No files found.
lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionError.php
0 → 100644
View file @
b7ee1fbc
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Driver\Mysqli\Exception
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliException
;
use
mysqli
;
/**
* @internal
*
* @psalm-immutable
*/
final
class
ConnectionError
extends
MysqliException
{
public
static
function
new
(
mysqli
$connection
)
:
self
{
return
new
self
(
$connection
->
error
,
$connection
->
sqlstate
,
$connection
->
errno
);
}
}
lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php
0 → 100644
View file @
b7ee1fbc
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Driver\Mysqli\Exception
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliException
;
use
mysqli
;
/**
* @internal
*
* @psalm-immutable
*/
final
class
ConnectionFailed
extends
MysqliException
{
public
static
function
new
(
mysqli
$connection
)
:
self
{
return
new
self
(
$connection
->
connect_error
,
'HY000'
,
$connection
->
connect_errno
);
}
}
lib/Doctrine/DBAL/Driver/Mysqli/Exception/FailedReadingStreamOffset.php
0 → 100644
View file @
b7ee1fbc
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Driver\Mysqli\Exception
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliException
;
use
function
sprintf
;
/**
* @internal
*
* @psalm-immutable
*/
final
class
FailedReadingStreamOffset
extends
MysqliException
{
public
static
function
new
(
int
$offset
)
:
self
{
return
new
self
(
sprintf
(
'Failed reading the stream resource for parameter offset %d.'
,
$offset
));
}
}
lib/Doctrine/DBAL/Driver/Mysqli/Exception/InvalidOption.php
0 → 100644
View file @
b7ee1fbc
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Driver\Mysqli\Exception
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliException
;
use
function
sprintf
;
/**
* @internal
*
* @psalm-immutable
*/
final
class
InvalidOption
extends
MysqliException
{
/**
* @param mixed $option
* @param mixed $value
*/
public
static
function
fromOption
(
$option
,
$value
)
:
self
{
return
new
self
(
sprintf
(
'Failed to set option %d with value "%s"'
,
$option
,
$value
)
);
}
}
lib/Doctrine/DBAL/Driver/Mysqli/Exception/StatementError.php
0 → 100644
View file @
b7ee1fbc
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Driver\Mysqli\Exception
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliException
;
use
mysqli_stmt
;
/**
* @internal
*
* @psalm-immutable
*/
final
class
StatementError
extends
MysqliException
{
public
static
function
new
(
mysqli_stmt
$statement
)
:
self
{
return
new
self
(
$statement
->
error
,
$statement
->
sqlstate
,
$statement
->
errno
);
}
}
lib/Doctrine/DBAL/Driver/Mysqli/Exception/UnknownType.php
0 → 100644
View file @
b7ee1fbc
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Driver\Mysqli\Exception
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliException
;
use
function
sprintf
;
/**
* @internal
*
* @psalm-immutable
*/
final
class
UnknownType
extends
MysqliException
{
/**
* @param mixed $type
*/
public
static
function
new
(
$type
)
:
self
{
return
new
self
(
sprintf
(
'Unknown type, %d given.'
,
$type
));
}
}
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
View file @
b7ee1fbc
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
namespace
Doctrine\DBAL\Driver\Mysqli
;
namespace
Doctrine\DBAL\Driver\Mysqli
;
use
Doctrine\DBAL\Driver\Connection
as
ConnectionInterface
;
use
Doctrine\DBAL\Driver\Connection
as
ConnectionInterface
;
use
Doctrine\DBAL\Driver\Mysqli\Exception\ConnectionError
;
use
Doctrine\DBAL\Driver\Mysqli\Exception\ConnectionFailed
;
use
Doctrine\DBAL\Driver\Mysqli\Exception\InvalidOption
;
use
Doctrine\DBAL\Driver\PingableConnection
;
use
Doctrine\DBAL\Driver\PingableConnection
;
use
Doctrine\DBAL\Driver\ServerInfoAwareConnection
;
use
Doctrine\DBAL\Driver\ServerInfoAwareConnection
;
use
Doctrine\DBAL\ParameterType
;
use
Doctrine\DBAL\ParameterType
;
...
@@ -73,7 +76,7 @@ class MysqliConnection implements ConnectionInterface, PingableConnection, Serve
...
@@ -73,7 +76,7 @@ class MysqliConnection implements ConnectionInterface, PingableConnection, Serve
});
});
try
{
try
{
if
(
!
$this
->
conn
->
real_connect
(
$params
[
'host'
],
$username
,
$password
,
$dbname
,
$port
,
$socket
,
$flags
))
{
if
(
!
$this
->
conn
->
real_connect
(
$params
[
'host'
],
$username
,
$password
,
$dbname
,
$port
,
$socket
,
$flags
))
{
throw
new
MysqliException
(
$this
->
conn
->
connect_error
,
$this
->
conn
->
sqlstate
??
'HY000'
,
$this
->
conn
->
connect_errno
);
throw
ConnectionFailed
::
new
(
$this
->
conn
);
}
}
}
finally
{
}
finally
{
restore_error_handler
();
restore_error_handler
();
...
@@ -163,7 +166,7 @@ class MysqliConnection implements ConnectionInterface, PingableConnection, Serve
...
@@ -163,7 +166,7 @@ class MysqliConnection implements ConnectionInterface, PingableConnection, Serve
public
function
exec
(
$statement
)
public
function
exec
(
$statement
)
{
{
if
(
$this
->
conn
->
query
(
$statement
)
===
false
)
{
if
(
$this
->
conn
->
query
(
$statement
)
===
false
)
{
throw
new
MysqliException
(
$this
->
conn
->
error
,
$this
->
conn
->
sqlstate
,
$this
->
conn
->
errno
);
throw
ConnectionError
::
new
(
$this
->
conn
);
}
}
return
$this
->
conn
->
affected_rows
;
return
$this
->
conn
->
affected_rows
;
...
@@ -257,9 +260,7 @@ class MysqliConnection implements ConnectionInterface, PingableConnection, Serve
...
@@ -257,9 +260,7 @@ class MysqliConnection implements ConnectionInterface, PingableConnection, Serve
}
}
if
(
!
in_array
(
$option
,
$supportedDriverOptions
,
true
))
{
if
(
!
in_array
(
$option
,
$supportedDriverOptions
,
true
))
{
throw
new
MysqliException
(
throw
InvalidOption
::
fromOption
(
$option
,
$value
);
sprintf
(
$exceptionMsg
,
'Unsupported'
,
$option
,
$value
)
);
}
}
if
(
@
mysqli_options
(
$this
->
conn
,
$option
,
$value
))
{
if
(
@
mysqli_options
(
$this
->
conn
,
$option
,
$value
))
{
...
...
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
View file @
b7ee1fbc
...
@@ -3,6 +3,10 @@
...
@@ -3,6 +3,10 @@
namespace
Doctrine\DBAL\Driver\Mysqli
;
namespace
Doctrine\DBAL\Driver\Mysqli
;
use
Doctrine\DBAL\Driver\FetchUtils
;
use
Doctrine\DBAL\Driver\FetchUtils
;
use
Doctrine\DBAL\Driver\Mysqli\Exception\ConnectionError
;
use
Doctrine\DBAL\Driver\Mysqli\Exception\FailedReadingStreamOffset
;
use
Doctrine\DBAL\Driver\Mysqli\Exception\StatementError
;
use
Doctrine\DBAL\Driver\Mysqli\Exception\UnknownType
;
use
Doctrine\DBAL\Driver\Result
;
use
Doctrine\DBAL\Driver\Result
;
use
Doctrine\DBAL\Driver\Statement
as
StatementInterface
;
use
Doctrine\DBAL\Driver\Statement
as
StatementInterface
;
use
Doctrine\DBAL\Driver\StatementIterator
;
use
Doctrine\DBAL\Driver\StatementIterator
;
...
@@ -89,7 +93,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -89,7 +93,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
$stmt
=
$conn
->
prepare
(
$prepareString
);
$stmt
=
$conn
->
prepare
(
$prepareString
);
if
(
$stmt
===
false
)
{
if
(
$stmt
===
false
)
{
throw
new
MysqliException
(
$this
->
_conn
->
error
,
$this
->
_conn
->
sqlstate
,
$this
->
_conn
->
errno
);
throw
ConnectionError
::
new
(
$this
->
_conn
);
}
}
$this
->
_stmt
=
$stmt
;
$this
->
_stmt
=
$stmt
;
...
@@ -111,7 +115,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -111,7 +115,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
assert
(
is_int
(
$column
));
assert
(
is_int
(
$column
));
if
(
!
isset
(
self
::
$_paramTypeMap
[
$type
]))
{
if
(
!
isset
(
self
::
$_paramTypeMap
[
$type
]))
{
throw
new
MysqliException
(
sprintf
(
"Unknown type: '%s'"
,
$type
)
);
throw
UnknownType
::
new
(
$type
);
}
}
$this
->
_bindedValues
[
$column
]
=&
$variable
;
$this
->
_bindedValues
[
$column
]
=&
$variable
;
...
@@ -128,7 +132,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -128,7 +132,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
assert
(
is_int
(
$param
));
assert
(
is_int
(
$param
));
if
(
!
isset
(
self
::
$_paramTypeMap
[
$type
]))
{
if
(
!
isset
(
self
::
$_paramTypeMap
[
$type
]))
{
throw
new
MysqliException
(
sprintf
(
"Unknown type: '%s'"
,
$type
)
);
throw
UnknownType
::
new
(
$type
);
}
}
$this
->
_values
[
$param
]
=
$value
;
$this
->
_values
[
$param
]
=
$value
;
...
@@ -146,7 +150,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -146,7 +150,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
if
(
$this
->
_bindedValues
!==
null
)
{
if
(
$this
->
_bindedValues
!==
null
)
{
if
(
$params
!==
null
)
{
if
(
$params
!==
null
)
{
if
(
!
$this
->
bindUntypedValues
(
$params
))
{
if
(
!
$this
->
bindUntypedValues
(
$params
))
{
throw
new
MysqliException
(
$this
->
_stmt
->
error
,
$this
->
_stmt
->
errno
);
throw
StatementError
::
new
(
$this
->
_stmt
);
}
}
}
else
{
}
else
{
$this
->
bindTypedParameters
();
$this
->
bindTypedParameters
();
...
@@ -154,7 +158,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -154,7 +158,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
}
}
if
(
!
$this
->
_stmt
->
execute
())
{
if
(
!
$this
->
_stmt
->
execute
())
{
throw
new
MysqliException
(
$this
->
_stmt
->
error
,
$this
->
_stmt
->
sqlstate
,
$this
->
_stmt
->
errno
);
throw
StatementError
::
new
(
$this
->
_stmt
);
}
}
if
(
$this
->
_columnNames
===
null
)
{
if
(
$this
->
_columnNames
===
null
)
{
...
@@ -201,7 +205,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -201,7 +205,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
}
}
if
(
!
$this
->
_stmt
->
bind_result
(
...
$refs
))
{
if
(
!
$this
->
_stmt
->
bind_result
(
...
$refs
))
{
throw
new
MysqliException
(
$this
->
_stmt
->
error
,
$this
->
_stmt
->
sqlstate
,
$this
->
_stmt
->
errno
);
throw
StatementError
::
new
(
$this
->
_stmt
);
}
}
}
}
...
@@ -243,7 +247,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -243,7 +247,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
}
}
if
(
!
$this
->
_stmt
->
bind_param
(
$types
,
...
$values
))
{
if
(
!
$this
->
_stmt
->
bind_param
(
$types
,
...
$values
))
{
throw
new
MysqliException
(
$this
->
_stmt
->
error
,
$this
->
_stmt
->
sqlstate
,
$this
->
_stmt
->
errno
);
throw
StatementError
::
new
(
$this
->
_stmt
);
}
}
$this
->
sendLongData
(
$streams
);
$this
->
sendLongData
(
$streams
);
...
@@ -263,11 +267,11 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -263,11 +267,11 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
$chunk
=
fread
(
$stream
,
8192
);
$chunk
=
fread
(
$stream
,
8192
);
if
(
$chunk
===
false
)
{
if
(
$chunk
===
false
)
{
throw
new
MysqliException
(
"Failed reading the stream resource for parameter offset ${paramNr}."
);
throw
FailedReadingStreamOffset
::
new
(
$paramNr
);
}
}
if
(
!
$this
->
_stmt
->
send_long_data
(
$paramNr
-
1
,
$chunk
))
{
if
(
!
$this
->
_stmt
->
send_long_data
(
$paramNr
-
1
,
$chunk
))
{
throw
new
MysqliException
(
$this
->
_stmt
->
error
,
$this
->
_stmt
->
sqlstate
,
$this
->
_stmt
->
errno
);
throw
StatementError
::
new
(
$this
->
_stmt
);
}
}
}
}
}
}
...
@@ -337,7 +341,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -337,7 +341,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
}
}
if
(
$values
===
false
)
{
if
(
$values
===
false
)
{
throw
new
MysqliException
(
$this
->
_stmt
->
error
,
$this
->
_stmt
->
sqlstate
,
$this
->
_stmt
->
errno
);
throw
StatementError
::
new
(
$this
->
_stmt
);
}
}
if
(
$fetchMode
===
FetchMode
::
NUMERIC
)
{
if
(
$fetchMode
===
FetchMode
::
NUMERIC
)
{
...
@@ -423,7 +427,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
...
@@ -423,7 +427,7 @@ class MysqliStatement implements IteratorAggregate, StatementInterface, Result
}
}
if
(
$values
===
false
)
{
if
(
$values
===
false
)
{
throw
new
MysqliException
(
$this
->
_stmt
->
error
,
$this
->
_stmt
->
sqlstate
,
$this
->
_stmt
->
errno
);
throw
StatementError
::
new
(
$this
->
_stmt
);
}
}
return
$values
;
return
$values
;
...
...
phpcs.xml.dist
View file @
b7ee1fbc
...
@@ -87,6 +87,7 @@
...
@@ -87,6 +87,7 @@
https://github.com/squizlabs/PHP_CodeSniffer/issues/2950
https://github.com/squizlabs/PHP_CodeSniffer/issues/2950
-->
-->
<exclude-pattern>
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php
</exclude-pattern>
<exclude-pattern>
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php
</exclude-pattern>
<exclude-pattern>
lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php
</exclude-pattern>
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/issues/2837 -->
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/issues/2837 -->
<exclude-pattern>
lib/Doctrine/DBAL/SQLParserUtils.php
</exclude-pattern>
<exclude-pattern>
lib/Doctrine/DBAL/SQLParserUtils.php
</exclude-pattern>
<exclude-pattern>
lib/Doctrine/DBAL/Tools/Dumper.php
</exclude-pattern>
<exclude-pattern>
lib/Doctrine/DBAL/Tools/Dumper.php
</exclude-pattern>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment