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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:15:40+00:00 2026-05-19T12:15:40+00:00

I have a .ini file for a configuration of my database and a constructor

  • 0

I have a .ini file for a configuration of my database and a constructor as follows:

function PHPRestSQL($iniFile = 'phprestsql.ini') {

    $this->config = parse_ini_file($iniFile, TRUE);

    if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD'])) {

        if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > 0) {
            $this->requestData = '';
            $httpContent = fopen('php://input', 'r');
            while ($data = fread($httpContent, 1024)) {
                $this->requestData .= $data;
            }
            fclose($httpContent);
        }

        $urlString = substr($_SERVER['REQUEST_URI'], strlen($this->config['settings']['baseURL']));
   $urlParts = explode('/', $urlString);

   $lastPart = array_pop($urlParts);
   $dotPosition = strpos($lastPart, '.');
   if ($dotPosition !== FALSE) {
    $this->extension = substr($lastPart, $dotPosition + 1);
    $lastPart = substr($lastPart, 0, $dotPosition);
   }
   array_push($urlParts, $lastPart);

   if (isset($urlParts[0]) && $urlParts[0] == '') {
    array_shift($urlParts);
   }

        if (isset($urlParts[0])) $this->table = $urlParts[0];
        if (count($urlParts) > 1 && $urlParts[1] != '') {
            array_shift($urlParts);
            foreach ($urlParts as $uid) {
                if ($uid != '') {
                    $this->uid[] = $uid;
                }
            }
        }

        $this->method = $_SERVER['REQUEST_METHOD'];

    }
}

After the constructor is set, it tries to connect with the database through the connect method

 function connect() {
            $database = $this->config['database']['type'];
            require_once($database.'.php');
            $this->db = new $database(); 
            if (isset($this->config['database']['username']) && isset($this->config['database']['password'])) {
                if (!$this->db->connect($this->config['database'])) {
                    trigger_error('Could not connect to server', E_USER_ERROR);
                }
            } elseif (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
       $this->config['database']['username'] = $_SERVER['PHP_AUTH_USER'];
       $this->config['database']['password'] = $_SERVER['PHP_AUTH_PW'];
                if (!$this->db->connect($this->config['database'])) {
                    $this->unauthorized();
                    exit;
                }
            } else {
                $this->unauthorized();
                exit;
            }
        }

Here’s a part of my .ini file config:

[database]
type = "mysql"
;type = "postgresql"
server = "neighborme.db.7346057.hostedresource.com"
database = "neighborme"
;username = "dbusername"
;password = "dbpassword"
foreignKeyPostfix = "_uid"

am I doing something wrong in the .ini file that makes it so that it can’t connect?

Why is this if statement not returning true:

if (isset($this->config['database']['username']) && isset($this->config['database']['password']))
  • 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-19T12:15:41+00:00Added an answer on May 19, 2026 at 12:15 pm

    well… maby because you have commented out username in your ini file?

    try changing ;username = "dbusername" to username = "dbusername"

    to be honest didnt really look much at the rest of the code because its so much.
    maby you can try to reduce it to the essential parts necessary to reproduce the problem?

    however what i mentioned above was what i saw at first sight

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

Sidebar

Related Questions

I have a .ini (configuration file) where I have mentioned the server name, Database
I have a perl script that's reading an INI file like this: [placeholder_title] Hostname
I have the following in a config.ini file: (Zend_Form_Element) site_status.name = site_status site_status.type =
I have the following line in my IsapiRewrite.ini file: RewriteRule ^/test-url.asp$ http://www.google.co.uk/ [R=301,L] But
I have a loop that finds duplicate lines in a .ini file. I can
I have not changed any of the configuration options for sessions in my php.ini.
I have two configuration files . One is ini one is php . They
What is the difference between configuration file and loaded configuration file? If ini file
I'am trying to rewrite zend framework configuration file from application.ini to application.yml format and
I'm coding a theme and i want to create a configuration file (maybe ini)

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.