swoole / library

📚 Swoole Library
https://wiki.swoole.com/#/library
Apache License 2.0
232 stars 59 forks source link

PDOException Original error code change #156

Closed fogelito closed 5 months ago

fogelito commented 1 year ago

Hello, We have an application using PDOProxy and PDO, We have an inconsistency problem when trying to match the original PDOException error code. https://github.com/swoole/library/blob/master/src/core/Database/PDOProxy.php#L61 This is how it is now $exception = new PDOException($errorInfo[2], $errorInfo[1]); should be $exception = new PDOException($errorInfo[2], $errorInfo[0]); since the original Error code is in position 0. Thank you very much

deminy commented 7 months ago

Current implement looks correct:

$exception = new \PDOException($errorInfo[2], $errorInfo[1]);

According to PHP documentation on method PDO::errorInfo(), error information is stored in an array with the following fields included (plus few more, if needed):

So

We should use $errorInfo[1] but not $errorInfo[0] as the exception code.

fogelito commented 7 months ago

You can see there is a difference between the original Exception. I get different error code value from the original PDOException.

deminy commented 6 months ago

@fogelito yep you are right. Fortunately, @NathanFreeman already got it fixed in Swoole 5.1.0 via PR #163 . Please feel free to give it a try and let us know if there is any concerns. Thanks

fogelito commented 6 months ago

Thank you 👍