Re: cvs: php4 /ext/mysql php_mysql.c

From: Date: Sun, 28 Apr 2002 16:49:43 +0000
Subject: Re: cvs: php4 /ext/mysql php_mysql.c
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11500@lists.php.net to get a copy of this message
Why not just have people query the database to see what db they are in? It might be a tad bit slower but it's foolproof. Andi At 06:38 28/04/2002 +0000, Jani Taskinen wrote:
sniper          Sun Apr 28 02:38:13 2002 EDT
Modified files:
    /php4/ext/mysql     php_mysql.c
Log: @- Added optional 3rd parameter to mysql_select_db() which makes it return @ the previously selected database name. (Jani) Index: php4/ext/mysql/php_mysql.c diff -u php4/ext/mysql/php_mysql.c:1.134 php4/ext/mysql/php_mysql.c:1.135
--- php4/ext/mysql/php_mysql.c:1.134    Sun Apr 28 01:36:05 2002
+++ php4/ext/mysql/php_mysql.c Sun Apr 28 02:38:12 2002 @@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: php_mysql.c,v 1.134 2002/04/28 05:36:05 sniper Exp $ */ +/* $Id: php_mysql.c,v 1.135 2002/04/28 06:38:12 sniper Exp $ */ /* TODO: @@ -769,13 +769,14 @@ } /* }}} */ -/* {{{ proto bool mysql_select_db(string database_name [, int link_identifier]) +/* {{{ proto bool mysql_select_db(string database_name [, int link_identifier [, bool return_prev_dbname]])
    Selects a MySQL database */
PHP_FUNCTION(mysql_select_db) {
-       zval **db, **mysql_link;
-       int id;
+       zval **db, **mysql_link, **ret_prevdb;
+       int id, ret_dbname=0;
        php_mysql_conn *mysql;
+       char *prev_db=NULL;
        switch(ZEND_NUM_ARGS()) {
                case 1:
@@ -791,20 +792,38 @@
                        }
                        id = -1;
                        break;
+               case 3:
+                       if (zend_get_parameters_ex(3, &db, &mysql_link, &ret_prevdb)==FAILURE) {
+                               RETURN_FALSE;
+                       }
+                       id = -1;
+                       convert_to_long_ex(ret_prevdb);
+                       ret_dbname = Z_LVAL_PP(ret_prevdb);
+                       break;
                default:
                        WRONG_PARAM_COUNT;
                        break;
        }
- - +
        ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", le_link, le_plink);
        convert_to_string_ex(db);
+
+       /* Get the previous database name */
+       if (ret_dbname && mysql->conn.db) {
+               prev_db=estrdup(mysql->conn.db);
+       }
        if (mysql_select_db(&mysql->conn, Z_STRVAL_PP(db))!=0) {
-               RETURN_FALSE;
+               RETVAL_FALSE;
+       } else if (prev_db) {
+               RETVAL_STRING(prev_db, 1);
        } else {
-               RETURN_TRUE;
+               RETVAL_TRUE;
+       }
+
+       if (prev_db) {
+               efree(prev_db);
        }
} /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.cvs (#11500) next »