Printable Version of Topic

Click here to view this topic in its original format

Forums _ Webmasters' Corner _ PHP MySQL Close

Posted by: Mikeplyts Jul 3 2010, 08:22 PM

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?

Posted by: mipadi Jul 4 2010, 10:48 AM

Well, $connection isn't actually initialized or set to anything in the code you have shown when calling 'database("close");'.

Posted by: Mikeplyts Jul 4 2010, 12:45 PM

Ah. Well, I just fixed it by simply using mysql_close() itself.