[drupal-devel] [bug] cannot connect to DB

beginner drupal-devel at drupal.org
Sat Sep 10 09:01:19 UTC 2005

Issue status update for 
Post a follow up: 

 Project:      Drupal
 Version:      cvs
 Component:    base system
 Category:     bug reports
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  beginner
 Updated by:   beginner
-Status:       patch (ready to be committed)
+Status:       patch (code needs review)
 Attachment:   http://drupal.org/files/issues/db-connect.database.mysql.inc.3.patch (560 bytes)

Did I say I was a beginner?
I was diffing against the already modified file.
This patch should be the good one (either that or expect to have a
flood of support request when drupal 4.7 comes out!).


Previous comments:

Fri, 09 Sep 2005 09:11:51 +0000 : beginner


I just downloaded and installed the cvs version. It works on my local
system, but it doesn't on the remote host. I checked dozens of time the
settings.php password, db, etc...
Drupal 4.6 works perfectly at the same host, using the same data base,
same user, same password (different prefix only, and different

I get an empty string as sql error message:
The MySQL error was: .

"Are you sure you have the correct username and password?

Yes. the same as existing drupal 4.6 install.

"Are you sure that you have typed the correct hostname?

Yes. idem.

"Are you sure that the database server is running?

Yes. working  for other installation.

To check that the settings.php was properly uploaded, I changed the
username in settings.php and uploaded again: the name changed in the
mention at the bottom of the new error page, but the mysql error is
still an empty string.

I do have a mysql error message if I change the username on my
The MySQL error was: Access denied for user: 'testerror at localhost'
(Using password: YES).
Currently, the username is testerror and the database server is



Fri, 09 Sep 2005 09:58:29 +0000 : beginner

If I suppress the @ I have the following error message:

Warning: Wrong parameter count for mysql_connect() in 
.../includes/database.mysql.inc on line 37

which seems strange in this context.
I have a - in the database host: out-data.org. Would that affect the
parsing of the variable in settings.php?


Fri, 09 Sep 2005 11:26:00 +0000 : beginner

It's definitely a php problem, not mysql settings:
we use PHP Version 4.2.3

by replacing the line:

$connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);

by its values:

$connection = mysql_connect('data.out-data.org', 'user', 'pass', TRUE, 2);

I still get the Wrong parameter count for mysql_connect() message...


4.6 works fine on the same host.


Fri, 09 Sep 2005 13:45:29 +0000 : beginner

Drupal 4.6:

  $connection = mysql_connect($url['host'], $url['user'], $url['pass'], TRUE) or die(mysql_error());

Drupal cvs:

$connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);

One more parameter has been added.

php.net/mysql_connect :
php 4.3.0   Added the client_flags parameter.

i.e. cvs Drupal and the coming 4.7 version will not work for php
versions < 4.3.0. My hosts unfortunately uses 4.2.3.


Sat, 10 Sep 2005 07:17:54 +0000 : beginner

I've seen that the list of requirements states php > 4.3.0, but I guess
I won't be the only one to be surprised to see that drupal doesn't work
AT ALL (no DB connection) when they upgrade.

Yet, by modifying the line above, to make it look like version 4.6, I
am able to use drupal cvs on my server with an older php version (I'm
on the lookout for other similar bugs).

I was trying to add a if loop, checking on the php version used, so
that we have:

if ($php_version >= 4.3.0){
  $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);
  $connection = mysql_connect($url['host'], $url['user'], $url['pass'], TRUE) or die(mysql_error());

but I cannot find in the documentation how this variable can be tested.

Also, once connected to the data base, a warning in admin/settings can
be added about the php version used.

Or do you really mean to shut out all the people who depend on the
(lack of) will of their host to upgrade php? If so, at the very least,
add a list item in the error message to remind people to check for the
php version.



Sat, 10 Sep 2005 08:22:23 +0000 : Prometheus6

Here's your test.

if (version_compare(phpversion(), '5', '<')) {
} else {


Sat, 10 Sep 2005 08:52:41 +0000 : beginner

Attachment: http://drupal.org/files/issues/db-connect.database.mysql.inc.patch (562 bytes)

Thanks Prometheus6.

here's a proper patch on includes/database.mysql.inc

tested on local (php 4.3.x) and remote (php 4.2.x).


Sat, 10 Sep 2005 08:56:09 +0000 : beginner

Attachment: http://drupal.org/files/issues/db-connect.database.mysql.inc.2.patch (560 bytes)

Am I doing things the wrong way round?? (I am beginner, and new to this
diff thing!)
here's the negative of the previous one...

More information about the drupal-devel mailing list