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

Error when calling GetAssoc() on an empty recordset #162

Closed
gavrochelegnou opened this issue Nov 30, 2015 · 9 comments
Closed

Error when calling GetAssoc() on an empty recordset #162

gavrochelegnou opened this issue Nov 30, 2015 · 9 comments
Labels
bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) pgsql PostgreSQL (Tier 1)
Milestone

Comments

@gavrochelegnou
Copy link

Hi, i'm having the following error :

Warning: array_keys() expects parameter 1 to be array, boolean given in /media/psf/WWW/ocms/include/adodb5/adodb.inc.php on line 3437

When i do a query that returns no row
$co->getAssoc('SELECT a,b FROM table WHERE 0')

Thanks a lot

@gavrochelegnou
Copy link
Author

I think the problem comes from this commit :
32a479a
When no rows are returned from the query $this->fields is not an array

@gavrochelegnou
Copy link
Author

Just created a pull request to test if $this->fields is an array, but i don't know if there is a better way to do it ?
#163

@mnewnham
Copy link
Contributor

Could you give your driver and adodb version please.

This looks to be a regression error in the mysqli driver in ADOdb 5.19 onwards.

Succeeds in oci8po, mysqli,mssqlnative in version 5.18
Succeeds in oci8po,mssqlnative version 5.19
Fails in mysqli version 5,19

@gavrochelegnou
Copy link
Author

I had the problem with mysqli in 5.20

@mnewnham
Copy link
Contributor

It looks like the problem is that the mysqli driver returns null in the 'fields' index in the recordset
for an empty query, while other drivers return array()., @dregad do you remember anything about this?

@dregad
Copy link
Member

dregad commented Nov 30, 2015

Not off the top of my head but I'll have a look tomorrow, maybe run git bisect too to identify the offending commit.

@mnewnham
Copy link
Contributor

mnewnham commented Dec 1, 2015

I agree that the problem is caused by commit 32a479a , but I think a more simple way would be

$cols = $this->_numOfFields;
if ($cols < 2) {
    return false;
}

if (!$this->fields)
    /*
   * Empty recordset, convert to empty array
   */
    return array();

$numIndex = blah,blah,blah

@dregad dregad added bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) labels Dec 1, 2015
@dregad dregad added this to the v5.20.1 milestone Dec 1, 2015
@dregad dregad changed the title Error whe calling GetAssoc() and the sql query returns no results Error when calling GetAssoc() and the sql query returns no results Dec 1, 2015
@dregad dregad added the pgsql PostgreSQL (Tier 1) label Dec 1, 2015
dregad added a commit that referenced this issue Dec 1, 2015
Regression introduced in v5.20.0.

Commit 32a479a removed the is_array()
check, resulting in a PHP warning when calling array_keys() on an empty
recordset, since $this->fields is false in this case.

Fixes #162
@dregad
Copy link
Member

dregad commented Dec 1, 2015

@gavrochelegnou The issue is fixed in commit 453f080 following @mnewnham's suggested implementation which I believe is more efficient than the one you proposed.

Feel free to patch your local installation, until I v5.20.1 is released officially.

Note that I confirmed this behavior on mysql(i) and pgsql, did not test on other drivers but most likely the problem is the same.

@dregad dregad changed the title Error when calling GetAssoc() and the sql query returns no results Error when calling GetAssoc() on an empty recordset Dec 1, 2015
@gavrochelegnou
Copy link
Author

Thanks a lot for your fast fix and awesome project !

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) pgsql PostgreSQL (Tier 1)
Projects
None yet
Development

No branches or pull requests

3 participants