#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Passing database connection variable to another page


    hi experts,

    hopefully you are all fine.

    i am working with php and oracle using oci. i want to pass database connection variable from login page to main page so that i can reuse it rather than creating another database session. is it possible ? if yes, how ?

    your advice needed.

    thanks in anticipation.

    Athar
    php student
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    why would you want to pass a database connection between two specific pages? That makes no sense to me.

    If you use PHP as a module (through mod_php), you can open a persistent connection that's shared among multiple requests. But the only reason to do that is to avoid the overhead of opening a new connection. If you have something else in mind, this is not the right solution.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0
    i just want to reuse database connection. how it will be done.
    please help. i am newbie.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    You could use the $_SESSION global to store an instance, but there's usually no reason to maintain instances.

    You usually just create a new instance. PHP is usually used differently to that of Java, C++ or C# (and other OOP) languages in that way. It's usually Stateless, meaning that state is not maintained between pages.

    Comments on this post

    • Jacques1 disagrees : No, you [I]cannot[/I] store database connections in a session. How should that even work? This is an external resource.
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by athar3432003
    i just want to reuse database connection. how it will be done.
    Um, didn't you see the link I gave you? On the bottom of the general explanation, there's even a link to the specific OCI function.

    However, I'm not sure if you know what you're doing... Have you actually done benchmarks and identified the database connection as the problem? Because like I said: That's the only reason to use persistent connections.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by codeadvisor
    You could use the $_SESSION global to store an instance
    I meant storing an instance of a database wrapper class in the $_SESSION variable.
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by codeadvisor
    I meant storing an instance of a database wrapper class in the $_SESSION variable.
    And what does this have to do with the question? He specifically wants to reuse the database connection, he didn't ask for what you can generally do with sessions.
  14. #8
  15. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    It is impossible to transfer resource type variables from one request to the next. They cannot be transferred in the session. A database connection is a resource type variable, so what you're asking cannot be done.

    You can use persistent connections as already mentioned. This effectively does the same thing that transferring the connection would do. However, you still need to "open" a new persistent connection on every page. The difference between a non-persistent and persistent connection is that when you "open" one, PHP might re-use an existing connection if you're using persistent connections instead of actually connecting to the database server again. However, persistent connections are rarely necessary.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo