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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:20:57+00:00 2026-05-23T07:20:57+00:00

Here is mysqli_connect() as defined in the PHP manual: mysqli_connect([ string $host = ini_get(mysqli.default_host)

  • 0

Here is mysqli_connect() as defined in the PHP manual:

mysqli_connect([ string $host = ini_get("mysqli.default_host")
               [, string $username = ini_get("mysqli.default_user")
               [, string $passwd = ini_get("mysqli.default_pw")
               [, string $dbname = ""
               [, int $port = ini_get("mysqli.default_port")
               [, string $socket = ini_get("mysqli.default_socket") ]]]]]] )

Should I just do this for all the arguments?:

class MyClass {
    private $conn;

    public function __construct($host = '') {
        if($host == '') {
            $host = ini_get('mysqli.default_host');
        }

        $this->conn = mysqli_connect($host);
    }
}

If I do that for all the method arguments will it correctly wrap mysqli_connect()? Is there a more elegant may to do it?

EDIT:

After seeing Francios’s answer and thinking about it a little more this seems like the best way to do it:

class MyClass {
    private $conn;

    public function __construct($host = '',
                                $username = '',
                                $passwd = '',
                                $dbname = '',
                                $port = 0,
                                $socket = '') {
        $this->conn = call_user_func_array('mysqli_connect', func_get_args());
    }
}

Would that wrap it correctly? The only thing that worries me is the $port because it is not a string.

  • 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-23T07:20:57+00:00Added an answer on May 23, 2026 at 7:20 am

    You could use call_user_func_array assuming that your class expects the parameters to be the exact same as mysqli_connect.

    class MyClass
    {
      private $conn;
    
      public function __construct()
      {
        $this->conn = call_user_func_array('mysqli_connect', func_get_args());
      }
    }
    

    With that said, the more elegant way is simply to extend the MySQLi class:

    class MyClass extends MySQLi
    {
      // Custom functions that extend the functionality of MySQLi can go here.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following program i picked from the php site (http://php.net/manual/en/mysqli.real-escape-string.php) and ran on my system
here is the code <?php session_start(); if(!isset($_SESSION['user_name'])) { header('Location: login.php'); } $conn = mysql_connect(localhost,
here is my mysql and php code layout: I have 3 tables tableA stores
Here: http://freshmeat.net/projects/myperl/ I need to enable PHP in MySQL
$databases = array(); $path = '/Path/To/Directory'; $main_link = mysqli_connect('localhost', 'USERNAME', 'PASSWORD'); $files = scandir($path);
I was writing a database handler class in PHP using the mysqli class and
I have created a file name database.php and here is it's content <?php #Start
Here's the problem: I started a swap today to use mysqli. No biggie, just
<?php class UBC_DB { private $db; public function connect() { $db = new mysqli('localhost',
Here it is my query to find username and password stored in mysql db

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.