bogdaniel Posted June 30, 2008 Share Posted June 30, 2008 /* Create the mysql class_exists */ class mysql { var $MYSQL_user = DBUSER;//MySQL username variable var $MYSQL_pass = DBPASS;//MySQL password variable var $MYSQL_host = DBHOST;//MySQL host variable - usually localhost var $MYSQL_db = DB;//MySQL database variable var $connect; var $get_db; function __construct( ) {//PHP 5 Constructor $this->Connect( ); } function mysql( ) {//PHP 4 constructor $this->Connect( ); } function Connect( ) {//Create a function called Connect that is responsible for connecting to the mysql db $this->connect = mysql_connect($this->MYSQL_host, $this->MYSQL_user, $this->MYSQL_pass)or die(mysql_error( )); $this->get_db = mysql_select_db($this->MYSQL_db) or die(mysql_error().__LINE__.__FILE__); }//End function function __destruct( ) {//Automatically closes the mysql connection mysql_close( $this->connect ); // here on line 43 i have an error } /* The queries */ function GetUserLogin($username, $password) { //Create a new function that requires you define the vars $username and $password when initiating $query = " SELECT username, id, password FROM `users` WHERE `username` = '". $username ."' AND `password` = '". $password ."' AND `banned` = 'n' LIMIT 1; ";//Create the MySQL query and make sure they arent banned return $query; //Return the query string } function GetUser( $username ) {//Create a function that gets a users info $query = " SELECT username, id, email FROM `users` WHERE `username` = '". $username ."' LIMIT 1; ";//Create the MySQL query and make sure they arent banned return $query; //Return the query string } function RegisterUser( $username, $password, $email, $ip ) {//Create a new function that requires certain variables $query = " INSERT INTO `users` (`username`, `password`, `email`, `ip`, `level`) VALUES ('". $username ."', '". $password ."', '". $email ."', '". $ip ."', '1'); ";//Create a MySQL query that inserts values into the database return $query; //Return the query string } }//End class Warning on line 43, mysql_close(): supplied argument is not a valid MySQL-Link resource, in C:\xampp\htdocs\ooptests\classes\mysql.php can someone help me please ? Quote Link to comment https://forums.phpfreaks.com/topic/112575-can-someone-help-me-please/ Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 it means whatever variable you have supplied in mysql_close(); doesn't exist, or is the wrong variable. ACE Quote Link to comment https://forums.phpfreaks.com/topic/112575-can-someone-help-me-please/#findComment-578155 Share on other sites More sharing options...
bogdaniel Posted June 30, 2008 Author Share Posted June 30, 2008 it means whatever variable you have supplied in mysql_close(); doesn't exist, or is the wrong variable. ACE i know that... but can you help me fix it ? cuz i don't have any ideea why it does like that all the time i used the form of writing and this is the first time that give me and error Quote Link to comment https://forums.phpfreaks.com/topic/112575-can-someone-help-me-please/#findComment-578159 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 to me it looks right. But I don't know OOP. Quote Link to comment https://forums.phpfreaks.com/topic/112575-can-someone-help-me-please/#findComment-578162 Share on other sites More sharing options...
PFMaBiSmAd Posted June 30, 2008 Share Posted June 30, 2008 Because the destructor is called when php terminates due to the die() statement when your connection fails, your mysql_close() is using a non-existent link. You would need to test if $this->connect is TRUE and only execute the mysql_close() statement if it is. Quote Link to comment https://forums.phpfreaks.com/topic/112575-can-someone-help-me-please/#findComment-578190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.