MySQLi Subsystem: Database unavailable

Discussion corner for Developers of Serendipity.
Post Reply
g00se
Regular
Posts: 10
Joined: Mon Jan 14, 2008 9:01 pm
Location: Berlin, Germany
Contact:

MySQLi Subsystem: Database unavailable

Post by g00se »

Hi!

I'm using s9y (1.2.1) with a local MySQL DB and the MySQLi driver subsystem of s9y. Someday I stopped the DB and didn't start a again.
So s9y said:
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'localhost' (1) in /private-backup/home/dennis/public_html/blog/include/db/mysqli.inc.php on line 239

Warning: mysqli_select_db() expects parameter 1 to be mysqli, boolean given in /private-backup/home/dennis/public_html/blog/include/db/mysqli.inc.php on line 241

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /private-backup/home/dennis/public_html/blog/include/db/mysqli.inc.php on line 250

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /private-backup/home/dennis/public_html/blog/include/db/mysqli.inc.php on line 250
I was a bit annoyed of the message and searched the mysqli.inc.php file and found the that the serendipity_db_connect() method assumes a always successful connect.

Now, s9y does check if the db_select is successful. If not I use the serendipity_db_probe.

The diff of mysqli.inc.php:
241c241
< mysqli_select_db($serendipity['dbConn'], $serendipity['dbName']) or serendipity_db_probe($serendipity, &$error);
---
> mysqli_select_db($serendipity['dbConn'], $serendipity['dbName']);
242a243
>
Also I set the error_reporting(0);
So s9y now says:
serendipity error: unable to connect to database - exiting.
I hope it's correct position for the check, but it work...
I really don't know if the check is done by the other DB drivers... So someone could have at it.

Good night!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: MySQLi Subsystem: Database unavailable

Post by garvinhicking »

Hi!

Yeah, actually serendipity emits straight MySQL/PHP errors. This eases up much of our forum support and debugging, it's much easier to tell people "your mysql server is not started". If we only had a generic message like "could not connect to database" we would not know, if the server is not there, the username does not exist, the permissions are not sufficient, etc.

So actually what would be needed would be simply "nicer" errors, but the errors themselve should IMHO be displayed. This is rather a fatal error, and IMHO since serendipity is often used by newbies, fatal errors should lead us on track to fix the error :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
g00se
Regular
Posts: 10
Joined: Mon Jan 14, 2008 9:01 pm
Location: Berlin, Germany
Contact:

Post by g00se »

Hi!

I got your point, but the error / warning messages are shown if you don't set error_reporting(0). My idea if someone is using s9y in a "productive" environment he / she is not interested in showing up error messages to an unexperienced user. Now he can (it's not a need) set the error reporting level to none. At this point s9y does generate on error a empty page, so a minimal error_message would be nice.

So the code does only add the a line with the message the database is unavailable message. The error reporting is a configuration option for the user.

Greetz
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Ah, I understand. But I don't get why the "or db_probe" command helps with that? The probing actually only fills an &$error array.

Actually, $serendipity['dbConn'] should contain no value in your error scenario, so basically this code in serendipity_config.inc.php:

Code: Select all

if (!serendipity_db_connect()) {
    $serendipity['lang'] = 'en';
    include(S9Y_INCLUDE_PATH . 'include/lang.inc.php');
    serendipity_die(DATABASE_ERROR);
}
should already emit the error message?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
g00se
Regular
Posts: 10
Joined: Mon Jan 14, 2008 9:01 pm
Location: Berlin, Germany
Contact:

Post by g00se »

I checked again a fresh installation and it does show the same output as my recommendation... So the change would do nothing.

:oops:

Sorry, for wasting your time Garv!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

No problem, that's what I'm here for. I was just wondering how the code would affect the display :)

Keep it coming! :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply