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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:13:43+00:00 2026-06-15T21:13:43+00:00

I have a file called config.php in which i defined 4 constants: <?php define(‘HOST’,’localhost’);

  • 0

I have a file called config.php in which i defined 4 constants:

<?php

define('HOST','localhost');
define('USER','root');
define('PASSWORD','');
define('DATABASE','some_database');

?>

What I want to do is call this script with request_once function inside the other php file called database.php which will use the constant from this file for connecting

<?php
  require_once('config.php');
  $connect = mysql_connect(HOST,USER,PASSWORD);
  $select_db = mysql_select_db(DATABASE);
?>

What i get returned is that the host,user,password and database are not defined. Why is that? This is a sample simplified code i used for connection but the essence of the problem is here. Thank you in advance.

  • 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-15T21:13:44+00:00Added an answer on June 15, 2026 at 9:13 pm

    PHP by default DO NOT SHOW Notices of undefined constants. So if you use a undefined constant PHP would simple treat that one as a string. For example,

    <?php
    //define('__TEST__', 'foo');
    
    print __TEST__; //Will print __TEST__ and raise E_NOTICE if it's enabled
    

    if you uncomment above define() PHP will print foo instead and won’t raise a notice.

    Personally I would suggest you to make a bit deeper test:

    0) Declare error_reporting(E_ALL) in config.php
    1) Check whether file exists and it readable before you include this
    2) Check whether constants are actually defined before you use them

    Finally, It would like this:

    File: config.php

    <?php
    
    error_reporting(E_ALL);
    
    define('HOST','localhost');
    define('USER','root');
    define('PASSWORD','');
    define('DATABASE','some_database');
    

    File: dbconnection.php

    <?php
    
    //require() will produce FATAL error if inclusion fails, so we're OK
    require_once('config.php'); 
    
    
    if ( defined('HOST') && defined('USER') && defined('PASSWORD') && defined('DATABASE') ){
    
     $connect = mysql_connect(HOST,USER,PASSWORD);
     $select_db = mysql_select_db(DATABASE);
    
    } else {
    
      trigger_error('Some constants are missing', E_USER_ERROR);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I need to pass a variable called $process_id to the file config/update.php which
I have a file called config.php, I want it to remain exactly as is,
I have a script that includes a config file (called accountsconfig.php) that contains a
I have a file called config.php with contents that looks like this: $setting_1 =
I have a file called config.json which have { book: { config: { uuid:
I have a file called config.yml in my /config folder of my rails application.
I have a file called middle.config that is deployed in the same directory as
I have a file called video_2.m4v on my computer, which is being used by
I have a file called header.php that I am including on every page on
I have a file called webpart.cs which is called by one of my masterpages

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.