Skip to content
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

MySQL Affected_Rows() returns number of rows selected instead of false for SELECT statements #604

Closed
mariobernheim opened this issue Jan 26, 2020 · 10 comments · Fixed by #729
Assignees
Labels
bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1)
Milestone

Comments

@mariobernheim
Copy link

mariobernheim commented Jan 26, 2020

Hi,

<?php
$sql = "SELECT * from subscribers WHERE number='".$number."' AND service_id='".$service_id."' LIMIT 1";
$rs  = $Conn->execute($sql);
if ($Conn->Affected_Rows()) {
    $active = $rs->fields['active'];    
    
    echo return_json_status("3","Number $number is subscribed to $service_id and is set active=$active");
    die("");
}
?>

For some reason this works... however, from the ADOdb Documentation, its not supposed to:

https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:affected_rows

Database: MySQL 5.7
Driver: Mysqli
PHP Version: PHP 7.0.33
ADOdb Version: V5.18

@mnewnham
Copy link
Contributor

Database? Driver? PHP Version? ADOdb Version?

@mariobernheim
Copy link
Author

Database: MySQL 5.7
Driver: Mysqli
PHP Version: PHP 7.0.33
ADOdb Version: V5.18

@mariobernheim
Copy link
Author

mariobernheim commented Jan 26, 2020

For references... I just tested these too

PHP Version: 7.2.25
ADOdb Version: v5.20.14

I do SELECT * from table limit 1 and Affected_Rows(); returns 1

@mnewnham mnewnham added bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) labels Jan 26, 2020
@mnewnham
Copy link
Contributor

This is due to a change in the behavior of the underlying mysqli_affected_rows(), which according to The PHP documentation, now acts as mysqli_num_rows() for SELECT statements. In order to maintain cross-database compatibility, we need to suppress this behavior.

@mnewnham mnewnham changed the title Affected_Rows() also works on SELECT MySQL Affected_Rows() returns number of rows selected instead of false for SELECT statements Jan 26, 2020
@mariobernheim
Copy link
Author

Thanks, so for all purposes, we should be able to use Affected_Rows(); on all SELECT's as well and can consider it reliable?

@mnewnham
Copy link
Contributor

No, you should not, because no other database supports it. The code will be changed so that it conforms to our standard, i.e. It will return false for SELECT statements

@mariobernheim
Copy link
Author

Should we use RecordCount(); instead?

@mnewnham
Copy link
Contributor

absolutely

@peterdd
Copy link
Contributor

peterdd commented Jan 24, 2021

Maybe the example on https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:affected_rows should include an insert query too, ideally with 2 or 3 row values in the insert query to have a number >1 on success.

And maybe remove the select example there to avoid confusion or add an explanation. It is unclear from the example if table act contains just no rows or means 'error', so the 'Return false' there might be misinterpreted.

Otherwise this issue can be closed?

@mnewnham
Copy link
Contributor

If you want to create a small example and paste it in here, I will happily update the documentation with it

mnewnham added a commit that referenced this issue May 1, 2021
The mysql affected rows returns a valid value when used against a SELECT statement. This does not conform to the ADOdb standard which requires it to return false
mnewnham added a commit that referenced this issue May 2, 2021
…s, see #604

The mysql affected_rows works as a rowcount() function when called against a select statement. It should return false for ADOdb statements.
@dregad dregad added this to the v5.21.1 milestone Aug 14, 2021
@dregad dregad linked a pull request Aug 14, 2021 that will close this issue
dregad pushed a commit that referenced this issue Aug 14, 2021
mysql_affected_rows() returns a valid value (i.e. works as a rowcount
function) when used against a SELECT statement.

This does not conform to the ADOdb standard, which requires it to 
return false.

Fixes #604 (PR #729)
@dregad dregad closed this as completed Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants