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 7966839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:32:31+00:00 2026-06-04T06:32:31+00:00

I’ve got a CI instance which connects to a Db and checks permissions before

  • 0

I’ve got a CI instance which connects to a Db and checks permissions before serving pages. If the page isn’t accessible to the current user, it redirects to a login page.

The login page, obviously, has permissions set so that it’s accessible to all users.

After a recent glitch, the database server came back up on a different IP address (thank you Amazon, EC2). This resulted in CI being unable to check permissions for any page – including Login. Since the code assumes anything other than a Yes is a No, it redirected to Login. The result was an infinite redirect loop.

While this exact problem shouldn’t happen again (Static elastic IP), I’d like to detect when the Db connection is down and handle it appropriately.

I’ve seen This SO Question which is what I’m trying to achieve but I’m not explicitly loading the database in any controllers, it’s in the autoload config file.

So,

How can I query the state of the Db connection from inside CI? Do I have to run a useless query and check if I get results back or is there a more elegant solution?

Edit: The check is currently being performed in a hook:

$hook['post_controller_constructor'] = array(
                                'class'    => 'AuthHook',
                                'function' => 'ValidateCredentials',
                                'filename' => 'auth.php',
                                'filepath' => 'hooks'
                                );
  • 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-04T06:32:32+00:00Added an answer on June 4, 2026 at 6:32 am

    “Since the code assumes anything other than a Yes is a No, it redirected to Login.”

    So therefore you only need to alter the login logic function to specifically check for a DB connection (and thus still auto-load the database).

    Use something like

     $result = $this->db->conn_id;  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.