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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:06:35+00:00 2026-05-23T23:06:35+00:00

I have 4 classes in PHP I use to signup a user, problem is

  • 0

I have 4 classes in PHP I use to signup a user, problem is I don’t know how to close the mysql connection.

Class calls:

single_connect->database->post->signup

When I implement mysql_close() in the singleton it breaks my code. My assumption is that as long as a signup object is created the classes it extends from are also “instantiated”. But this does not appear to be the case.

I had to comment out the mysql_close to allow this to work. Note that my singleton uses the database link to determine if it exists wrather then a pointer to itself like most Singletons.

/*single_connect*/

class single_connect
  {
  private static $_db_pointer = NULL;
  private function __destruct() 
    {
    //mysql_close();
    }
  private function __construct()
    {
    self::$_db_pointer = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_DATABASE);
    }
  public static function get_connection()
    {
    if(self::$_db_pointer == NULL)
      {
      return new self();
      } 
    }
  }

/*database*/

abstract class database
  {
  protected function __construct()
    {
    single_connect::get_connection();
    }
  protected static function query($query)
    {
    $result = mysql_query($query) or die(mysql_error());
    return $result;
    }
  }

/*post*/

class post extends database
  {
  public $_protected_arr=array();
  protected function __construct()
    {
    parent::__construct();
    $this->protect();
    }
  protected function protect()
    {
    foreach($_POST as $key => $value)
      {
      $this->_protected_arr[$key] = mysql_real_escape_string($value);
      }
    }
  }

/*signup*/

class signup extends post 
  { 
 ...
  • 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-23T23:06:35+00:00Added an answer on May 23, 2026 at 11:06 pm

    Connections are automagically being closed when script execution finishes. So if there is no tremendous amount of time between the last database operation and the end of the script I would not bother to explicitly close the connection.

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

Sidebar

Related Questions

I have two classes in a PHP application, B extending A for example. Class
I have learned how to use classes in PHP and so far I have
I have the following PHP Classes class.property.php class.location.php class.amenity.php class.category.php all four classes handles
I have 3 classes (3 files): a.class.php b.class.php c.class.php I want to extend class
I am working on some PHP classes, I have a session class used to
A quick question about best practice with PHP classes. I have seen people use
I have a LinkedIn API class that I've written for PHP that makes use
I have a conceptual problem to do with PHP classes and error handling.. Below
So I have 3 classes in this situation. Connection.php Engineer.php Status.php Both Engineer and
If I have some php classes inside a namespace com\test and want to import

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.