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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:30:27+00:00 2026-05-19T22:30:27+00:00

I am new to OOP having this code and am having a problem creating

  • 0

I am new to OOP having this code and am having a problem creating a database connection, what could be the problem? Strangely am not getting any errors yet i cannot make any MYSQL INSERTS or SELECTS from the database because the connections have not been made

    //include the file that contains variables necessary for database connection
require_once 'configurations.php';

//This is the class that will be used for the MySQL Database transactions
class MySQLDatabase
{
    private $database_connection;

    //constructor class
    function __construct()
    {
        $this->open_connection();
    }

    public function open_connection()
    {
        $this->database_connection = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
        if (!$this->database_connection)
        {
            //if the connection fails, return the following message and indicate the error
            die("Could not connect to the MYSQL Database due to: " . mysql_error());
        }
        else
        {
            //if the connection is made to MYSQL database, then select the database being used 
            $database_selection = mysql_select_db(DATABASE_NAME, $this->database_connection);

            //if the database to be used cannot be selected, return this error
            if (!$database_selection)
            {
                die ("Could not select the database due to: " . mysql_error());
            }
        }
    }//end of function open database
}//end of class MySQLDatabase

$database_transactions = new MySQLDatabase();
  • 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-19T22:30:27+00:00Added an answer on May 19, 2026 at 10:30 pm

    There are a few things I would consider…

    • You write function __construct()
      but all the other methods and
      properties are either public or
      private – use public function
      __construct()
    • Why is the method open_connection()
      public? Should it be called from
      “outside”? Do you want someone
      to execute this method directly
      from an object? Think about making it private function open_connection() -> http://de.php.net/manual/en/language.oop5.visibility.php
    • Why use die() in OOP? Do you really
      want to output the error message to
      the user? It isn’t secure to do that.
      It’s better to throw an Exception and work with try{} and catch{} to handle an error -> http://de.php.net/manual/en/language.exceptions.php

    Are you really sure you’re getting no error messages at all? Show use your query method… Your code should be fine so far (at least you should get an error on screen with die() if something is not correct).

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

Sidebar

Related Questions

I've created this game thing in order to learn OOP and I'm having trouble
I am just getting into OOP and framework design. I have started by using
I'm pretty new to OOP and Zend. So far I'm trying to set up
I'm a Java newbie, and also new to OOP. I have been a procedural
I'm trying to understand OOP and having some trouble with a couple of concepts
Quick question. I have been Googling this all morning, but it's either not there,
I'm having issues adding a sub result to a result in Codeigniter. Not sure
I am having a lot of trouble understanding how the Android context menu works.
Hope this is clear enough: class myParent(): def __init__( self ): self.parentNumber = 5

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.