connect
| From: | David Tandberg-Johansen | Date: | Mon, 14 Aug 2000 09:32:09 +0000 |
| Subject: | connect | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-2031@lists.php.net to get a copy of this message | ||
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???