-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explain why the number of affected rows can be a string #5872
Conversation
Mysqli is the only driver to support this feature. https://www.php.net/manual/en/mysqli.affected-rows.php
@@ -21,7 +21,7 @@ public function __construct(private readonly PDO $connection) | |||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |||
} | |||
|
|||
public function exec(string $sql): int|string | |||
public function exec(string $sql): int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PDO::exec()
returns int|false
.
@@ -49,7 +49,7 @@ public function quote(string $value): string | |||
return "'" . str_replace("'", "''", $value) . "'"; | |||
} | |||
|
|||
public function exec(string $sql): int|string | |||
public function exec(string $sql): int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqlsrv_rows_affected
returns int|false
.
@@ -78,7 +78,7 @@ public function quote(string $value): string | |||
* @throws Exception | |||
* @throws Parser\Exception | |||
*/ | |||
public function exec(string $sql): int|string | |||
public function exec(string $sql): int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oci_num_rows
returns int|false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct that only MySQLi supports row counts > PHP_INT_MAX
at the moment. But we should not close the door here: If one of the other extensions at some point decides to support this as well, we should not be forced to issue a new major release of DBAL. Since all driver connection classes are final
, I think your return type changes are fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not close the door here: If one of the other extensions at some point decides to support this as well, we should not be forced to issue a new major release of DBAL.
It is wise to anticipate this. I'm OK to revert the type to int|string
on all the driver connections, including SQLite3\Connection
which is currently int
.
With your last sentence, I'm not sure what's your thoughts.
String return type is conditional on the driver used. Co-authored-by: Alexander M. Turek <[email protected]>
Seen #5879. Thank you. |
Thanks! |
Summary
Mysqli is the only driver that can return a string when the number of affected rows is greater that
PHP_INT_MAX
(doc)Adding a comment in order to make clear for users they can safely cast the result of
Connection::executeStatement()
to(int)
when they don't use this driver, or the executed statement cannot update so many rows.