Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    107
    Thanks
    1
    Thanked 0 Times in 0 Posts

    connection problem with connection class

    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 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();
        
    ?>

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    it's not errors, it's warnings, you can switch them off with error_reporting
    you've commented right db connection strings in construct function
    try to replace your construct function with next:
    PHP Code:
    public function __construct() {
             
    mysql_connect(DB_PATHDB_USERDB_PASS);
    mysql_select_db(DB_NAME);


    or may be you just have empty result for your request
    Last edited by poyzn; 11-11-2010 at 10:35 PM.

  • #3
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    838
    Thanks
    15
    Thanked 9 Times in 9 Posts
    It is basically telling you that the $result isn't valid.... double check that you are sending the FetchSArray a valid MySQL statement and that the MySQL statment produces no errors.
    PHP Code:
    public function Query($sql) {
         
    $result mysql_query($sql) or $error mysql_error();
         if(
    $result) {
              return 
    $result;
         }
         else {
              echo 
    '<strong>MySQL Error: </strong> '.$error;
              return 
    false;
         }

    The above addition to your code will check if the $result is valid and if not will display an on screen message of what the MySQL error is.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    if you want to use classes, think about using MySQLi or PDO. those are already class based and are not outdated like the mysql_* functions.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •