Help - Search - Members - Calendar
Full Version: PHP MySQL Close
Forums > Resource Center > Webmasters' Corner
Mikeplyts
While I'm at it, I seem to have ran into something very odd. Very, very odd. So, to connect to the MySQL database and close the connection, I use a function. Like so:
CODE
<?php
function database($call) {
    global $database;

    switch($call) {
        case 'connect':
            $connection = mysql_connect($database['server'], $database['username'], $database['password']);
            mysql_select_db($database['name'], $connection);
            break;
        case 'close':
            mysql_close($connection);
            break;
    }
}
?>


$database is an array in a configuration file where I have the necessary values set to connect to the MySQL database (which, by the way, are correct). And before someone goes ape-shit on me for extending this out to such a time-wasting function, I'm using it for cleaner syntax on most of all my other pages (instead of having to type out the $connection variable, selecting the database, and [at times] closing it for each page). This actually worked just fine before, but now it's generating this error:
CODE
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in _________________/includes/functions.php on line 144


Hilfe?
mipadi
Well, $connection isn't actually initialized or set to anything in the code you have shown when calling 'database("close");'.
Mikeplyts
Ah. Well, I just fixed it by simply using mysql_close() itself.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.