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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:59:50+00:00 2026-06-03T07:59:50+00:00

My situation: Folder structure is /resources/website/inc/ (/resources/ is where configs are stored, /website/ holds

  • 0

My situation:
Folder structure is /resources/website/inc/ (/resources/ is where configs are stored, /website/ holds index.php and /inc/

I have defined my constants for db connection in config.php / in resources folder.

   define ( 'DB_HOST', 'localhost' );
   define ( 'DB_USER', 'my_username' );
   define ( 'DB_PASSWORD', 'my_password' );
   define ( 'DB_NAME', 'my_database' );

In index.php the database is accessed and displays data.

I’ve come to the conclusion that it am trying to use the defined constants in config.php with a connect statement in index.php, but the constants are not passing.

This is my connect statement:

$connect = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or 
                         die("MySQL Error: " . mysql_error());
$db = mysql_select_db(DB_NAME) or die("MySQL Error: " . mysql_error());

When i add both pieces into the config.php it works fully, but i wanted to have connect and close of connection in various areas, i do not want to have to define the variables again

  • 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-03T07:59:51+00:00Added an answer on June 3, 2026 at 7:59 am

    You need to require (include) the config file in every other file that can be accessed through the web server.

    Something alone the lines of:

    config.php

    define ( 'DB_HOST', 'localhost' );
    define ( 'DB_USER', 'my_username' );
    define ( 'DB_PASSWORD', 'my_password' );
    define ( 'DB_NAME', 'my_database' );
    

    public/index.php

    require_once __DIR__ . '/../config.php';
    // The rest of you code here
    

    public/contact.php

    require_once __DIR__ . '/../config.php';
    // The rest of you code here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My situation is simple. I have this in my program: File folder = new
So I have the following situation. My root folder is /var/www/html. If I have
I have the following situation. My project has a main.scala.html file and a folder
Situation: I have an index page which loads pages into it with ajax as
I have different layout files for different screens size like Folder Structure: layout layout-large
I have a cakephp application made by previous employees, its structure is defined as
I got file index.php that includes index.php file in admin folder <?php require 'admin/index.php';
Hi I wanted help in a situation where I have a folder called 'slides'
I am in a situation where I have to use the drawable folder of
I have s simple question: Situation: When I rightclick Source Files folder and select

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.