Re: connect

From: Date: Tue, 15 Aug 2000 02:09:39 +0000
Subject: Re: connect
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-2053@lists.php.net to get a copy of this message
I'm not sure, but the error sounds as if the script's trying to reconnect after already having done so. FYI, here's the logon I use. Hope it's useful. cheers, curt require("BLglobals.php") ; // the above contains only the values // for $host, $user, $password, $dbname #--------------- # connect to db #--------------- if (!($link=mysql_pconnect ($host, $user, $password))) { displayerrmsg(sprintf("error connecting to host %s, by user %s",$host, $user)) ; exit() ; } #----------- # select db #----------- if (!mysql_select_db($dbname, $link)) { displayerrmsg(sprintf("Error in selecting %s database", $dbname)) ; displayerrmsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link))) ; exit() ; } ------------------------------------------- David Tandberg-Johansen wrote: > > Hello all! > I am wondering if anyone can say what I am doing wrong here! > I have created an config.php file with the following in it: > > *********congfig.php**************** > $hostname = "localhost"; > $username = "username"; > $password = "password"; > $dbName = "dbName"; > $table1 = "table1"; > $table2 = "table2"; > $table3 = "table3"; > > $today = date("Ymd"); > > function connect($db) > { > MYSQL_CONNECT($GLOBALS["hostname"], $GLOBALS["username"], > $GLOBALS["password"]) OR DIE("Unable to connect to database"); > @mysql_select_db( "$db") or die( "Unable to select database $db"); > } > > function count($table) > { > connect($GLOBALS["dbName"]); > $result = mysql_db_query($GLOBALS["dbName"], "select count(*) as id from > $table "); > $num = mysql_result($result,0,"id"); > echo $num; > } > *******END config.php******************* > > And I created an test file test.php. > > ****test.php**************************** > <?PHP > require ("config.php"); > echo count($GLOBALS["table2"]); > ?> > ****END test.php************************ > > I have read tha to accsess the variable outside the functions I had to > spesify the "globals". SO I did. But I got only error message: > > Fatal error: Cannot redeclare connect() in config.php on line 11 > > I dont understand why??? > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#2053) next »