connection problem with conneciton class`

Discussion in 'PHP' started by dizyn, Nov 11, 2010.

  1. #1
    I am having issues with connect
    I see following errors:
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/myfolder/public_html/myfolder/config.php on line 58

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/myfolder/public_html/myfolder/config.php on line 45

    here is my code:
    
    
    <?php
    
    	// site info
    	define('HTTP_PATH', 'http://go/twi.tter.me/');
    	define('URL_SHFT', 1);
    	define('FS_PATH', dirname(__FILE__) . '/');
    	
    	// database info
    	define('DB_PATH', 'localhost');
    	define('DB_USER', 'login');
    	define('DB_PASS', 'pass');
    	define('DB_NAME', 'db');
    	
    
      // database class
      
      class MySqlStuff {
    
    	public $connection = null;
    	public $database = null;
    
    	public function __construct() {
    	     
    //		$this->connection = mysql_connect(DB_PATH, DB_USER, DB_PASS);
    //		$this->database = mysql_select_db(DB_NAME);
    		$this->connection = mysql_connect("localhost", "login", "pass");
    		$this->database = mysql_select_db("mydb");
    
    		return true;
    
    	}
    
    	public function Query($sql) {
    
    		$result = mysql_query($sql);
    		return $result;
    	
    	}
    
    	public function FetchArray($sql) {
    
    		$result = $this->Query($sql);
    		$array = array();
    
    		while($row = mysql_fetch_assoc($result)) {
    
    			$array[] = $row;
    			
    		}
    
    		return $array;
    		
    	}
    	
    	public function FetchSArray($sql) {
    
    		$result = $this->Query($sql);
    		$array = mysql_fetch_assoc($result);
    
    		return $array;
    		
    	}
    	
    	public function InsertID() {
    	
    		return mysql_insert_id();
    		
    	}
    	
    	public function NumberRows($sql) {
    	
    		$result = $this->Query($sql);
    		return mysql_num_rows($result);
    		
    	}
    
      }
      
      // connect to database
      $mysqlstuff = new MySqlStuff();
    	
    ?>
    
    
    PHP:
     
    dizyn, Nov 11, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    argument is not a valid MySQL result resource, is either no connection to the database or wrong query.

    try checking mysql_connect, when you mysql_connect return value is a resource
     
    bartolay13, Nov 11, 2010 IP
  3. dixcoder

    dixcoder Member

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #3
    i am sure you sql query is not correct please paste the query too
     
    dixcoder, Nov 12, 2010 IP