In MySQL database connections default to localhost, so it is normally ok to run MySQL commands without specifying that option and have it just connect to the localhost. In settings.php if you don't include the 'host' array value for a given database definition the following error will be given:
Notice: Undefined index: host in DatabaseConnection_mysql->__construct() (line 37 of includes/database/mysql/database.inc).
The site will still work, but the above error still displays. Adding the 'host' value makes the error go away.
My reason for opening this issue is that the error shouldn't display, it should default to transparently connecting to localhost as normal if the 'host' value is undefined.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | database_host_undefined-1403500-12.patch | 1.77 KB | superspring |
| #9 | 1403500-db-host-value-9.patch | 877 bytes | ramlev |
| #7 | 1403500-db-host-value-7.patch | 827 bytes | c31ck |
| #4 | drupal-no.db_.hostname-1403500-5477100.patch | 805 bytes | AndrewBoag |
Comments
Comment #1
damienmckennaThis is the line in question:
If the 'host' value doesn't exist it'll end up with a string like the following:
mysql:host=;port=3306With PHP 5.2.4 this works and will connect to the localhost database.
Given the PDO documentation does not define what is supposed to happen when this is blank or not present, the current result is that it behaves as if the value '127.0.0.1' was provided (note, I have not verified to see if it tries connecting via a socket or TCP/IP).
The questions are:
Comment #2
AndrewBoag commentedI think that the host value should be required field. It's a core part of the database connection details and would not normally be left out inside an application db connection details.
It would be simple enough to add a default value which would stop this error.
Comment #3
c31ck commentedIn any case the code you mention should check if $connection_options['host'] is set. If it's not set, it should either provide a sensible default (localhost) or it should show a clear error message. Furthermore, the documentation in default.settings.php isn't entirely clear on which parameters are required and which ones are optional.
Comment #4
AndrewBoag commentedI have attached a patch that throws a warning message in the instance that the host is not defined.
Comment #5
swentel commentedSomehow, I feel tempted to mark this won't fix. The 'host' input field on the install screen is set to required, so there's no room for mistakes there. I'm not sure about drush, but that seems for more advanced users anyway. The patch feels like babysitting to me, I'd rather document this instead of adding an isset.
Comment #6
AndrewBoag commentedNo disagreement from me. When I was writing the patch, it did seem like overkill.
Comment #7
c31ck commentedHow about defaulting to localhost if no value is set? The port value is handled the same way.
Comment #8
damienmckenna@c31ck: +1 for that idea.
Comment #9
ramlev commentedSince the structure of files in drupal 8 has changed since the last patch was created, i have fixed it in this one.
Comment #10
ramlev commentedComment #11
swentel commentedIf we want to path this, we should check the postgres and sqlite driver as well. Also, other people should set issues to RTBC, not the patch author itself.
Comment #12
superspring commentedThis patch applies the 'default host' parameter to both Postgres and MySQL. Sqlite does not require a host parameter.
Comment #13
AndrewBoag commentedAfter a year or so away from this issue I see that things have sort of stalled.
The reality is that this is not really a critical bug in that if you have set up your Drupal DB settings properly, you won't be affected here.
If DB "host" ain't defined when it should be ... that is just sort of wrong and broken.
I'm closing this but please some-one reopen if they feel passionately about it.