Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:40:57+00:00 2026-05-29T06:40:57+00:00

I currently make an Oracle connection like this: $c = oci_connect(‘username’, ‘password’, ‘host’); which

  • 0

I currently make an Oracle connection like this:

$c = oci_connect('username', 'password', 'host');

which I use my oci8 queries like this:

$s = oci_parse($this->c, $query);
oci_execute($s);

However, every time I want to query, I create a new connection i.e. I do $c = ... many times. This is a silly thing to do. What is the correct or best way to make a single Oracle connection and use that connection from anywhere in the program? I can make $c I global variables but global variables aren’t nice.

Thanks very much :).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:40:58+00:00Added an answer on May 29, 2026 at 6:40 am

    Couldn’t you use a static variable, like this…

    class DbHandler {
        private static $_mOciHandle;
    
        private function __construct() {}
    
        GetHandle ($u, $p, $dsn, $charset) {
            if (!isset(self::$_mOciHandle))
                self::$_mOciHandle = oci_connect ($u, $p, $dsn, $charset);
            return self::$_mOciHandle;
            }
    }
    

    It still renders your database handle (indirectly) global, but you only ever have one connection, and this way it’s protected from “accidental” update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to make a sectioned table like this: Section 1: Entry
I am currently investigating how to make a connection to a SQL Server database
I'm currently using Oracle db11g on Red Hat Enterprise Linux 5.0. I make an
I currently work with an Oracle database and we use stored procedures for all
I make use of: NetBeans IDE 6.7.1, GlassFish v2.1, Oracle 10g XE, JAVA 6
I am currently creating a small table in Oracle and am unsure of which
We're distributing a commercial application for Linux and we currently make it available for
My company runs a video website. We currently make our content available via streaming,
We've got a C++ Project that currently uses Make on Linux to build. I'd
I am currently trying to make a navigation-menu where an active-class is applied to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.