By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,644 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

OOP help

P: 1
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4.  /*
  5. Create the mysql class_exists
  6. */
  7.  
  8.     class mysql
  9.     {
  10.  
  11.         var $MYSQL_user = DBUSER;//MySQL username variable
  12.         var $MYSQL_pass = DBPASS;//MySQL password variable
  13.         var $MYSQL_host = DBHOST;//MySQL host variable - usually localhost
  14.         var $MYSQL_db = DB;//MySQL database variable
  15.  
  16.         var $connect;
  17.         var $get_db;
  18.  
  19.         function __construct(   ) {//PHP 5 Constructor
  20.  
  21.             $this->Connect(   );
  22.         }
  23.  
  24.         function mysql(   ) {//PHP 4 constructor
  25.  
  26.             $this->Connect(   );
  27.  
  28.         }
  29.  
  30.         function Connect(   ) {//Create a function called Connect that is responsible for connecting to the mysql db
  31.  
  32.             $this->connect = mysql_connect($this->MYSQL_host, $this->MYSQL_user, $this->MYSQL_pass)or die(mysql_error(   ));
  33.               $this->get_db = mysql_select_db($this->MYSQL_db) or die(mysql_error().__LINE__.__FILE__);
  34.         }//End function
  35.  
  36.  
  37.         function __destruct(   ) {//Automatically closes the mysql connection
  38.             mysql_close(   $this->connect   );
  39.  
  40.         }
  41.  
  42. /*
  43. The queries
  44. */
  45.  
  46.         function GetUserLogin($username, $password) { //Create a new function that requires you define the vars $username and $password when initiating
  47.  
  48.             $query = "
  49.             SELECT username, id, password FROM `users` 
  50.             WHERE
  51.             `username` = '". $username ."' 
  52.             AND 
  53.             `password` = '". $password ."' 
  54.             AND
  55.             `banned` = 'n' 
  56.             LIMIT 1; 
  57.             ";//Create the MySQL query and make sure they arent banned
  58.             return $query; //Return the query string
  59.         }
  60.  
  61.  
  62.         function GetUser(   $username   ) {//Create a function that gets a users info
  63.  
  64.             $query = "
  65.             SELECT username, id, email FROM `users` 
  66.             WHERE 
  67.             `username` = '". $username ."' 
  68.             LIMIT 1; 
  69.             ";//Create the MySQL query and make sure they arent banned
  70.  
  71.             return $query; //Return the query string
  72.         }
  73.  
  74.  
  75.         function RegisterUser(   $username, $password, $email, $ip   ) {//Create a new function that requires certain variables
  76.             $query = "
  77.             INSERT INTO `users`
  78.             (`username`, `password`, `email`, `ip`, `level`)
  79.             VALUES
  80.             ('". $username ."', '". $password ."', '". $email ."', '". $ip ."', '1');
  81.             ";//Create a MySQL query that inserts values into the database
  82.  
  83.             return $query; //Return the query string
  84.         }
  85.  
  86.  
  87.     }//End class
  88.  
  89.  
  90.  
  91.  
  92.  
  93. ?>

on line 43 i have a problem gives error

Warning on line 43,
mysql_close(): 5 is not a valid MySQL-Link resource,
in C:\xampp\htdocs\xgame\classes\mysql.php


can someone help me please ?
Jun 30 '08 #1
Share this Question
Share on Google+
3 Replies


Markus
Expert 5K+
P: 6,050
Is there any need for $this->connect.
When mysql_close is called, it closes the last opened connection.
Jun 30 '08 #2

pbmods
Expert 5K+
P: 5,821
Heya, fantomel.

You might as well get rid of the PHP-5-style constructor; this class is a PHP 4 class, and PHP 5 is backwards compatible.

My guess is that at the time the destructor is called, mysql_close() has already been called somewhere else.
Jul 2 '08 #3

10K+
P: 13,264
1.) That's a warning not an error
2.) Why don't you post the code you executed that gave you the warning.
Jul 2 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.