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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:52:56+00:00 2026-05-30T15:52:56+00:00

I want to load a configuration file in a class. Here is the content

  • 0

I want to load a configuration file in a class. Here is the content of config.php

<?php
$__error_reporting_level=1;
$server='localhost';
$user='root';
$password='';
$dbase='eauction';
?>

Content of sql.php

<?php
include ('config.php');
error_reporting($__error_reporting_level);

class sql
{
 function connect()
 {
  $connections = mysql_connect($server, $user,$password) or die ('Unabale to connect to the database');
  mysql_select_db($dbase) or die ('Unable to select database!');
  return;
 }

 function login($email, $pwd)
 {
  $this->connect();
  $result = $this->qry("SELECT uid,nameF FROM user WHERE email='".$email."' AND password='".$pwd."'");
  $row=mysql_fetch_array($result);
  if (mysql_num_rows($result)>0)
   return array($row[0],$row[1]);
  else
   return array(0,0);
 }
}
?>

I execute the code using

include ('core/sql.php');
$obj = new sql;
$data=$obj->login($email,$pwd);
print_r($data);

I get this error

Unable to select database!

Ignore mysql injection issue, I just need to execute the code perfectly

  • 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-30T15:52:57+00:00Added an answer on May 30, 2026 at 3:52 pm

    can do it this way.. the issue on your code must be that the variable you declare in config.php is not accessible. you can make it global or try this code of mine.

    <?php
    class ConnectionSettings {
        private $hostname = 'localhost';
        private $username = 'root';
        private $password = '';
        private $db = 'cordiac_db';
        protected $connLink;
    
        // protected 'connect()' method
        protected function connect(){
    
            // establish connection
            if(!$this->connLink = mysql_connect($this->hostname, $this->username, $this->password)) {
                throw new Exception('Error connecting to MySQL: '.mysql_error());
            }
    
            // select database
            if(!mysql_select_db($this->db, $this->connLink)) { 
                throw new Exception('Error selecting database: '.mysql_error());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to load key/values configuration pairs stored in XML file. To bind a
I want to load some images into my application from the file system. There's
I want Intellisense support when writing App.config sections or XML configuration files for components
I want to have some custom configuration (read in from file) available throughout my
It seem Mono ignores dllmaps in the local configuration file. I want to port
I want to load xml file into spring bean for further processing. I know
I m trying to load properties file to create a configuration. namely foo.properties. What
My Code: // Read in Xml-file XmlDocument doc = new XmlDocument(); doc.Load(C:/Web.config); XmlNode d
I want to load one or more DLLs dynamically so that they run with
I want to load a desktop application, via reflection, as a Control inside another

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.