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

The Archive Base Latest Questions

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

in the past I have used smt like: $con = mysql_connect(localhost, root, root) or

  • 0

in the past I have used smt like:

$con = mysql_connect("localhost", "root", "root") or
die("Could not connect: " . mysql_error());

mysql_select_db("xxx");

But now, I’ve noticed everybody started using smt like this:

if (!defined('DB_HOST')) define('DB_HOST','localhost');
if (!defined('DB_USER')) define('DB_USER','root');
if (!defined('DB_PASS')) define('DB_PASS','root');
if (!defined('DB_NAME')) define('DB_NAME','xxx');

What’s different about their usage? For example echoing, filtering..

Thanks for help

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

    Well, none of them are wrong, it’s your choice. I think the second alternative is more like a good practice. But my statement is valid only if you define it in one file and require_once in the others. Example:

    db_config.php:

    if (!defined('DB_HOST')) define('DB_HOST','localhost');
    if (!defined('DB_USER')) define('DB_USER','root');
    if (!defined('DB_PASS')) define('DB_PASS','root');
    if (!defined('DB_NAME')) define('DB_NAME','xxx');
    

    query.php:

    require_once db_config.php;
    $con = mysql_connect(DB_HOST, DB_USER, DB_NAME) or
    die("Could not connect: " . mysql_error());
    mysql_select_db("xxx");
    

    But why? Imagine that you want to change your database name, user or password. If you have code mysql_connect("localhost", "root", "root") every time you needed it, a change of plans will make you go through a lot of re-coding. But if you define them in one place as the second alternative does, you won’t have to rewrite a lot of files.

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

Sidebar

Related Questions

In the past I have used something like this to send form fields in
In the past I have used jqgrid like in the examples here . I
In the past I have used MAPISendMail to launch Outlook (or whatever the desired
In the past I have used Managed Direct X and DirectShow.Net to play a
Excuse my limited knoweldge here. In the past I have used Steve Sanderson's method
I have used JMS in the past to build application and it works great.
I have used Hibernate in the past and I share many people's frustration with
I have used valgrinds massif tool to monitor memory usage in the past. Does
I have used the code supplied in the following CodeProject article in the past
I do used IntelliJ IDEA as my development environment at past and I have

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.