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

PHP 8.0 compatibility: function 'setConnectionParameter' (mysqli) #693

Closed
deining opened this issue Mar 10, 2021 · 6 comments
Closed

PHP 8.0 compatibility: function 'setConnectionParameter' (mysqli) #693

deining opened this issue Mar 10, 2021 · 6 comments
Labels
bug documentation mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) PHP8 PHP 8 compatibility issues

Comments

@deining
Copy link

deining commented Mar 10, 2021

Versions:

  • php 8.0.3
  • mysql Ver 15.1 Distrib 10.5.9-MariaDB
  • adodb 5.21.0

Following your advice given in #686, I tried to use function setConnectionParameter.
Unfortunately, this leads to another error:

Stackstrace:

Uncaught TypeError: mysqli_options(): Argument #2 ($option) must be of type int, string given in /my_path/adodb/drivers/adodb-mysqli.inc.php:148
Stack trace:
#0 /my_path/adodb/drivers/adodb-mysqli.inc.php(148): mysqli_options()
#1 /my_path/adodb/adodb.inc.php(705): ADODB_mysqli->_connect()
#2 /my_path/my.php(10): ADOConnection->Connect()
#3 {main}\n  thrown in /my_path/adodb/drivers/adodb-mysqli.inc.php on line 148

My code looks like:

include('adodb/adodb.inc.php');
$db = ADONewConnection('mysqli');
$db->setConnectionParameter('CharacterSet','utf8mb4');
$db->Connect("host", "user", "passphrase", "database");

Thanks for investigating the issue.

@dregad dregad added bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) PHP8 PHP 8 compatibility issues labels Mar 10, 2021
@dregad
Copy link
Member

dregad commented Mar 10, 2021

You need to use the predefined constants to identify the option, and not some arbitrary string. In your case:

$db->setConnectionParameter(MYSQLI_SET_CHARSET_NAME,'utf8mb4');

MYSQLI_SET_CHARSET_NAME

That said, the code should not choke on this, so I'll keep this open to fix this

@deining
Copy link
Author

deining commented Mar 10, 2021

You need to use the predefined constants to identify the option

Thanks for clarification. It now works as expected.

That said, the code should not choke on this, so I'll keep this open to fix this

I agree. Thanks for your efforts.

Another topic: The documentation of the setConnectionParameter function mentions usage with DB2 and SQl server databases only. Would be great if usage in case of MySQL (and PostgreSQL) were added, too.

@dregad
Copy link
Member

dregad commented Mar 10, 2021

Another topic: The documentation of the setConnectionParameter function mentions usage with DB2 and SQl server databases only. Would be great if usage in case of MySQL (and PostgreSQL) were added, too.

I was actually updating that as you posted... Please check again
https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:setconnectionparameter

@dregad
Copy link
Member

dregad commented Mar 10, 2021

@mnewnham I was wondering why you defined the setConnectionParameter() method as final (see #158, 2e72fe5), this prevents overriding it in a specific driver (mysqli in this case) to add error handling.

Of course we could also do the check in ADODB_mysqli::_connect() as well, but it seems cleaner to me to catch the error early. Thoughts ?

@mnewnham
Copy link
Contributor

Clearly a mistake. Please revert

dregad added a commit that referenced this issue Mar 10, 2021
This was a mistake, as discussed in [[1]].

Fixes #694

[1]: #693 (comment)
dregad added a commit that referenced this issue Mar 13, 2021
Add error handling for $parameter type: since mysqli_options() requires
an integer, the function now fails and returns false (or throws an
exception if enabled) when given a non-numeric value.

Fixes #693
dregad added a commit that referenced this issue Mar 13, 2021
Make sure the parameter is numeric, to prevent PHP Warning or TypeError
exception when calling mysqli_options(), and if the call fails (e.g.
because an unsupported option constant was provided, throw an exception
or display an error message instead of silently failing.

Fixes #693
@dregad
Copy link
Member

dregad commented Mar 13, 2021

That said, the code should not choke on this, so I'll keep this open to fix this

PR #701 addresses the problem of ADODB_mysqli->_connect() throwing a TypeError (on PHP 8) or a Warning (on earlier PHP versions) when processing an invalid parameter.

dregad added a commit that referenced this issue Mar 27, 2021
Make sure the parameter is numeric, to prevent PHP Warning or TypeError
exception when calling mysqli_options(), and if the call fails (e.g.
because an unsupported option constant was provided, throw an exception
or display an error message instead of silently failing.

Fixes #693
@dregad dregad closed this as completed in aa20883 Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug documentation mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) PHP8 PHP 8 compatibility issues
Projects
None yet
Development

No branches or pull requests

3 participants