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

  • Home
  • SEARCH
  • 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 8070605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:26:17+00:00 2026-06-05T13:26:17+00:00

With an OO language I often use a factory design pattern to connect to

  • 0

With an OO language I often use a factory design pattern to connect to a DB:

// Connect to Redis ( PHP )
protected function get_redis() {
   static $redis = false;
   if( $redis === false ) {
      $redis = new Predis\Client(Configure::read('redis.db'));
   }
   return $redis;
}

I done quite a lot of C but never any big projects. I want to know how to connect to a Redis DB (or any DB) in C without opening more than one connection. I know I can use a global variable but is there a better way ? I don’t want to force the factory pattern – it’s OO. Has anyone got any examples ?

Many thanks.

  • 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-06-05T13:26:18+00:00Added an answer on June 5, 2026 at 1:26 pm

    I am going to disagree with you here. Factory method does not necessarily put an OO stamp on your code. It’s just a pattern for creating things.

    If you don’t want to create more than one connection, you can control that in the get_connection function. This is another application for this pattern.

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

Sidebar

Related Questions

I often have to design client APIs for use by other programmers. The language
i am still new to the Java language and libraries... i often use this
When I use an imperative language I often write code like foo (x) {
As developer, I am often interested in new language feature that can make your
This is non-language-specific, but I'll use examples in C# . Often I face the
I often hear complaints that programming languages that make heavy use of symbols for
I often open .aspx file. I used to do language -> j -> javascript.
Language: OO PHP 5+ DB: MySQL I am trying to insert data from a
Language: PHP I have a form which asks users for their educational details, course
Can anyone please explain a recursive function to me in PHP (without using Fibonacci)

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.