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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:35:50+00:00 2026-05-30T02:35:50+00:00

I am a php noob. I am trying to make a database connection file

  • 0

I am a php noob. I am trying to make a database connection file into a class (does it need to be private, static or something?). Netbeans is now throwing up errors and I get 500 internal server error when I try and run it from a browser. I think I have missed something simple ! Thanks

<?php
class config{

//define server, username, password and database
var $db_host="domain.co.uk.mysql"; 
var $db_user="user";                 
var $db_password="password";    
var $db_name="dbname"; 
var $db_tableprefix="tableprefix"; 
//connect to MySQL server
mysql_connect($db_host,$db_user,$db_password);

//select the database
@mysql_select_db($db_name) or die ("Unable to select database: " . mysql_error());

}
?>
  • 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-30T02:35:51+00:00Added an answer on May 30, 2026 at 2:35 am

    None of your statements are in methods. And you have not instantiated the class and called on a method that would perform your statements.

    Classes are for object oriented programming. Your class has just old regular procedural code in a class which will not work.

    <?php
        class config{
    
            //define server, username, password and database
            var $db_host="domain.co.uk.mysql"; 
            var $db_user="user";                 
            var $db_password="password";    
            var $db_name="dbname"; 
            var $db_tableprefix="tableprefix"; 
    
            public function connect() {
                //connect to MySQL server        
                mysql_connect($db_host,$db_user,$db_password);
    
                //select the database
                @mysql_select_db($db_name) or die ("Unable to select database: " . mysql_error());
            }
    
        }
    
        $var = new config();
        $var->connect();
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a PHP noob. I have a database that I will update weekly with
I'm sorta a noob at these things but I'm trying to make a simple
I'm a mod_rewrite noob and I'm getting a headache trying to figure out something
Really quick noob question with php: I'm trying to create a conditional statement where
I apologize in advance, I am a PHP noob! I have form with some
PHP, as we all know is very loosely typed. The language does not require
PHP stores its session information on the file system of the host of the
Okay background i am a js and ajax noob. I work mainly in php
I'm trying to piece together a php script to output different text depending on
I am new to programming PHP and am trying to validate a field in

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.