Jump to content

Problem with classes


coldkill

Recommended Posts

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
[code]/*-------------------------------------------------------------------------*/
    //    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;
    }[/code]

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

The function "init_db_conn" is in another calling file with this code
[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 );
        }
        
        
    }[/code]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Yep:
[code]
/**
*    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            
                        );[/code]
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.