ODBC's heuristic for guessing if DSN or connection string could be better
Description
The following code:
<?php
$conn = odbc_connect("DSN=*LOCAL", null, null);
var_dump($conn);
Resulted in this output:
bool(true)
But I expected this output instead:
PHP Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in /home/calvin/src/test-heuristic.php on line 3
bool(false)
The ODBC drivers use strchr(db/dsn, ";") (well, procedural uses strstr, but same deal) to detect if the string the user passed into the constructor is a connection string or not. However, this isn't accurate for connection strings with a single entity (i.e. a DSN=dsn - seems useless versus just using the DSN name, but valid and still useful if you're i.e. building a connection string programatically).
One solution might be to use the ODBC quoting rules like in my PR #8307, but there's valid DSNs that use the characters that Microsoft claims have to require quoting. For example, IBM's Db2 for i driver installs a *LOCAL DSN in odbc.ini (on IBM i versions of the driver for loopback, but the point remains, can i.e. easily just add a DSN of that name to your own system), which would make the simple DSN name case invalid for that DSN.
Another solution is to just scan for a subset of those characters - = might be enough to add, or instead of ;.
PHP Version
8.2.0-dev
Operating System
Fedora 35
I have to admit that the current implementation is rather suboptimal. I'm reluctant to categorize this as bug, though; IMO it's more like a feature request, or at least something we better don't touch for any of the stable PHP versions.
Right, it could be called either. I do agree changing this in older releases would be a surprise change in behaviour.
A lot of the motivation for the ODBC cleanups I'm trying to do is having to explain the difference in behaviour (the abstraction leak) to our users at work. There, it does seem like a bug from that perspective (i.e. why does one work but not the other?), so that's why I leaned towards calling it one here.
Fixed by #8748