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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:01:40+00:00 2026-05-24T06:01:40+00:00

<?php class connection { public $host, $username, $password, $database; function __construct($host, $username, $password, $database)

  • 0
<?php

class connection
{
    public $host, $username, $password, $database;

    function __construct($host, $username, $password, $database)
    {
        $this->host = $host;
        $this->username = $username;
        $this->password = $password;
        $this->database = $database;
    }

    function MySQLi()
    {
        return new mysqli($this->host, $this->username, $this->password, $this->database);
    }

    public function __destruct()
    {
        mysqli_close($this->MySQLi());
    }
}

?>

Is destructing mysqli connections inside of a class a bad idea? Or should one stick to standard mysqli objects and just close connections like this?

$bedtime = new mysqli(....);
$bedtime->query("INSERT..");
$bedtime->close();
  • 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-24T06:01:41+00:00Added an answer on May 24, 2026 at 6:01 am

    The deconstruction won’t work, because if you do something like

    $conn = $connection->MySQLi(.......);
    

    even if you unset($connection), $conn will remain active.

    Stick with normal objects if that’s your target.

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

Sidebar

Related Questions

<?php class test_class { public function __construct() { } public function doLogin($username,$password) { include(connection.php);
I use symfony's ProjectConfiguration.class.php for configuring doctrine's connection: public function configureDoctrineConnectionCertby(Doctrine_Connection $conn) { $conn->setListener(new
<?php class UBC_DB { private $db; public function connect() { $db = new mysqli('localhost',
I am trying to build a PHP class to check the username and password
class SingleTon { private static $instance; private function __construct() { } public function getInstance()
class.mysql.php has 2 classes: MySQL and MySQLResult class.mysql.php: <?php /** * MySQL Database Connection
<?php class Functions { public static function extendSql($dbhost, $dbuser, $dbpass, $dbname) { // making
I currently have my PHP class variables set up like this: class someThing {
I'm using this php class ( http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php ) for creating the different sized images
I have done this before but am quite new to mysqli and prepared statements

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.