Log In · Register

 

Help Topic Rules and Requirements

For a list of all requirements and guidelines pertaining to posting a new Help topic, please click here.

This Month's Contests | Staff Member of the Month | Hosts Looking for Hostees | Hostees looking for Hosts | BigBookofResources

Submission Guidelines

 
Reply to this topicStart new topic
PHP MySQL Close
Mikeplyts
post Jul 3 2010, 08:22 PM
Post #1


Mel Blanc was allergic to carrots.
*******

Group: Official Designer
Posts: 6,371
Joined: Aug 2008
Member No: 676,291



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
post Jul 4 2010, 10:48 AM
Post #2


Senior Member
******

Group: Administrator
Posts: 2,647
Joined: Apr 2008
Member No: 639,265



Well, $connection isn't actually initialized or set to anything in the code you have shown when calling 'database("close");'.
 
Mikeplyts
post Jul 4 2010, 12:45 PM
Post #3


Mel Blanc was allergic to carrots.
*******

Group: Official Designer
Posts: 6,371
Joined: Aug 2008
Member No: 676,291



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

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members: