Passing MDB2 connection to functions

Discussion in 'PHP' started by nuhonvaomat, May 12, 2010.

  1. #1
    I am a C and PERL developer needing PHP newbie help.



    I have a main function that passes a db connection to a few function.



    in a.php:


    PHP Code:
    
    //I�don't�initialize�or�anything
    
    myconnect($dbc);
    
    
    
    in�myconnect�function,�I�call�another�function:
    
    anotherfx($dbc)
    
    {
    
    �����//�call�one�more�function
    
    �����onemorefx($dbc)
    
    �����{
    
    ����������$dbc�=&�MDB2::connect(...);
    
    ����������//�everything�fine�here,�and�can�call�methods,�etc.
    
    �����}
    
    
    
    �����//�from�here�and�on�out,�I�have�problems
    
    �����$dbc->query(...);��//�gives�me�Fatal�error:�Call�to�a�member�function�q uery()�on�a�non�object...
    
    }�
    
    
    
    
    
    
    PHP:
    How should I be passing this MDB2 connection around?
    More Information:

    1. One of the advantages of MDB2 over PEAR::DB is that it offers a number of different ways of providing a DB connection - either lazy (MDB2::factory()), optimistic (MDB2::connect()) or singleton (
    2. Is it a good idea to pass an MDB2 instance around as a session variable, or should i create a new connection to the database everytime a page is loaded?
    3. However, if you use DataObject over MDB2, you have to initialize the connection 00:13 < MikeSeth> probably a separate adapter is needed 00:13 <
    4. the performance of the PHP to Oracle connections, by choosing the best connection function, passing the character set on connection, and optimizing common connection steps
    5. Odd connection problems; NetGear RsngeMax Next Router (Networking Hardware Configuration); MDB2 SQL Connection (Visual Basic 4 / 5 / 6)
    6. One of the advantages of MDB2 over PEAR::DB is that it offers a number of different ways of providing a DB connection - either lazy (
    7. Translation2 uses MDB2 as an archive foundation, so you have either to create a MDB2 connection, or reuse an existing one by passing the database
    8. empty strings) - don't pass objects by ref in the Decorator, as it's deprecated - better check for existing connections in the MDB and MDB2 drivers - fixed assignment
    9. Also, iirc MDB2 contains functions to return data from a query directly
     
    nuhonvaomat, May 12, 2010 IP
  2. webria

    webria Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you will write a singleton class for DB instance, it will be good. You will find article on net.
     
    webria, May 14, 2010 IP