Jump to content


Photo

Problem with classes


  • Please log in to reply
5 replies to this topic

#1 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 01 April 2006 - 06:22 PM

I made a class which has all my database stuff in like connection, querying, fetching stuff etc etc but with the connect it doesn't accept the vars $this->obj['sql_usr'] etc etc. Everything else appears to work find except this function which i have now changed the var names to the actual values so it will work.

Any ideas?

Thanks in advance,
Cold

Heres the code of the function
/*-------------------------------------------------------------------------*/
    //    Connect to the db
    /*-------------------------------------------------------------------------*/
    function connect()
    {
        
        if( $this->obj['persistant'] )
        {
            $this->connection_id    =    mysql_pconnect(    
                                                        "localhost"    ,
                                                        "---"    ,
                                                        "---"    ,
                                                        0                                                        
                                                        );
        }
        else
        {
            $this->connection_id    =    mysql_connect(
                                                        "localhost"    ,
                                                        "---"    ,
                                                        "---"    ,
                                                        0    
                                                        );
        }
        
        if( ! $this->connection_id    )
        {
            $this->fatal_error();
            return FALSE;
        }
        
        if ( ! mysql_select_db("cold_coldfire") )
        {
            $this->fatal_error();
            return FALSE;
        }
        
        return TRUE;
    }

The function is called on the index with
$cfclass->init_db_conn();

The function "init_db_conn" is in another calling file with this code
//=================================
    //    INIT: DB
    //=================================
    function init_db_conn(){
        
        $this->vars['sql_type'] = ! $this->vars['sql_type'] ? 'mysql' : strtolower($this->vars['sql_type']);
        require_once( KERNEL_PATH.'class_db.php' ); //<- page with the connect function
            
        /**
        *    New DB driver
        */
        $this->DB        = new db_driver;
        
        /**
        *    Set DB vars
        */
        $this->DB->obj['sql_db']    =    $this->vars['sql_db'];
        $this->DB->obj['sql_usr']    =    $this->vars['sql_user'];
        $this->DB->obj['sql_host']    =    $this->vars['sql_host'];
        $this->DB->obj['sql_pass']    =    $this->vars['sql_pass'];
        $this->DB->obj['sql_type']    =    $this->vars['sql_type'];
        $this->DB->obj['persistant']    =    '0';
        
        /**
        *    Load query file
        */
        
        $this->DB->obj['sql_query_file'] = ROOT_PATH.'sources/sql/'.$this->vars['sql_type'].'_queries.php';        
        
        /**
        *    Constants
        */
        define( "SQL_TYPE"    , $this->vars['sql_type'] );
        define( "DB_CLASS_LOADED" , TRUE );
        
        /**
        *    Connect to the db... finally ¬¬
        */
        $this->DB->connect();
        $this->db_conn        = '1';
        
        /**
        *    All done :D
        */
        if( ! defined( "DB_LOADED" ) )
        {
            define( "DB_LOADED" , TRUE );
        }
        
        
    }



You can learn alot from reading the manual

#2 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 02 April 2006 - 12:40 AM

To add to my problem:

I've tried making another class and accessing the query function (which works in the other places it exists) using $cfclass->DB->query("QUERY"); but i get this error [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Fatal error: Call to a member function on a non-object in /home/cold/public_html/kernel/class_temp.php on line 50[/quote]

I am using extends cfclasses to get the function but it still doesn't work.

Any ideas?
Thanks,
Cold


You can learn alot from reading the manual

#3 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 02 April 2006 - 04:30 PM

OK it seems to only not work with class psuedo vars ie $this->var['sql_user'] etc etc.
Any ideas?


You can learn alot from reading the manual

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 02 April 2006 - 06:20 PM

Where going to need to see more code. As isits very difficult to see what is going on. Do you have a property obj defined?

#5 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 02 April 2006 - 07:59 PM

Yep:
/**
*    DB Object array
*     Holds key information
*/
var $obj            = array(
                        "sql_db" => ""                ,
                        "sql_user" => "root"                ,
                        "sql_pass" => ""            ,
                        "sql_host" => "localhost"    ,
                        "persistant" => "0"            ,
                        "sql_type"    =>    "mysql"        ,
                        "cached_queries" =>    array()    ,        
                        "sql_query_file" => ""        ,
                        "force_new"    =>    0            
                        );
All the information does get to the function but for some reason it still doesn't work.

I tried echoing a few of the obj values and they all displayed properly.


You can learn alot from reading the manual

#6 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 03 April 2006 - 07:54 PM

::Bumb::
Still need help please.


You can learn alot from reading the manual




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users