Page 1 of 1

Fix for serendipity_db_connect()

Posted: Sat Nov 08, 2003 9:11 pm
by Rasmus
db_connect() should return the existing connection if it is already there. Here is a patch against current CVS:

Code: Select all

Index: serendipity_db_mysql.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_db_mysql.inc.php,v
retrieving revision 1.15
diff -u -r1.15 serendipity_db_mysql.inc.php
--- serendipity_db_mysql.inc.php        20 Sep 2003 03:43:56 -0000      1.15
+++ serendipity_db_mysql.inc.php        8 Nov 2003 20:08:07 -0000
@@ -87,10 +87,11 @@
     global $serendipity;

     if (isset($serendipity['dbConn'])) {
-        return;
+        return $serendipity['dbConn'];
     }

     $serendipity['dbConn'] = mysql_connect($serendipity['dbHost'], $serendipity['dbUser'], $serendipity['dbPass']);
+       if(!$serendipity['dbConn']) echo mysql_error();
     mysql_select_db($serendipity['dbName']);
     return $serendipity['dbConn'];
 }
[/code]

Fix for fix

Posted: Sat Nov 08, 2003 9:14 pm
by Rasmus
Oops, didn't notice I had left some debug in. Get rid of that echo there obviously.

Code: Select all

Index: serendipity_db_mysql.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_db_mysql.inc.php,v
retrieving revision 1.15
diff -u -r1.15 serendipity_db_mysql.inc.php
--- serendipity_db_mysql.inc.php        20 Sep 2003 03:43:56 -0000      1.15
+++ serendipity_db_mysql.inc.php        8 Nov 2003 20:12:38 -0000
@@ -87,7 +87,7 @@
     global $serendipity;

     if (isset($serendipity['dbConn'])) {
-        return;
+        return $serendipity['dbConn'];
     }


Posted: Sun Nov 09, 2003 5:45 pm
by tomsommer
In what connection is this needed, I agree with the idea... but is it needed?

Posted: Sun Nov 09, 2003 6:28 pm
by Rasmus
Uh, you need it because you test the return code in serendipity_config.inc.php:

Code: Select all

/*
 *   Attempt to connect to the database
 */
if (!serendipity_db_connect()) {
    die(DATABASE_ERROR);
}

Posted: Sun Nov 09, 2003 7:28 pm
by tomsommer
Fair enough