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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:56:14+00:00 2026-06-15T17:56:14+00:00

I have a function I used to use with my scripts. openDBConn() and closeDBConn()

  • 0

I have a function I used to use with my scripts. openDBConn() and closeDBConn() These both called the mysql_connect() function. Used as seen below

openDBConn();
$car_model = getCarModel($car_id);
$car_color = getCarColor($car_id);
closeDBConn();

doing it this way also allows me to do the following

openDBConn();
mysqlStartTranscation();

upgradeCarColor($car_id);
addNewWing($car_id);

mysqlCommit();
closeDBConn();

Dilemma now is, if I move to mysqli, I will need to pass the connection link.

I have also read that mysql_* is being deprecated the questions I have are:

  1. How much time do i have before most of my functions stop working?
  2. Is there any current or future way of accessing the current mysqli connection as adding extra parameters to my functions will be a pain?
  3. Is there any proper coding way of accessing the current mysqli connection link in a procedural manner. If not in procedural, whats the best in an OOP manner?
  • 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-06-15T17:56:15+00:00Added an answer on June 15, 2026 at 5:56 pm
    1. You have all the time in the world since they will never stop working on their own!
    2. Yes, there are several ways of doing this.
    3. Yes, but there is no one-size-fits-all solution. Every situation is different and what’s proper for you particular situation may not be proper for every situation.

    First, the old ext/mysql is deprecated as of PHP 5.5.0, but it will never stop working entirely as the extension itself will eventually be moved into the PHP PECL repository (when it comes time to remove it). However, we’re not there yet and you can only be affected when and if you chose to upgrade to that version of PHP. There is no exact time determined for the removal of the extension.

    Second, you can use a variable to store the database connection just as the old ext/mysql extension was doing for you behind the scenes. The trick was you weren’t aware of what it was doing (it uses the last open connection you created when you called mysql_connect and uses that everytime you call something like mysql_query to access the database).

    You can do this with a static variable in your function using procedural style….

    function openDBConn() {
        static $link;
        if (!isset($link)) {
          $link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
        }
        return $link; // returns the link
    }
    

    Or you can do this with a Class Static Variable using OOP…

    Class MyDBConnect {
    
        public static $link;
    
        public function openDBConn() {
            if (!isset(static::$link)) {
                static::$link = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
            }
        }
    
    }
    

    I want to encourage you for using the newer APIs and I commend you for it, but I also want to caution you as you move forward. When you start to port your functions over from the old ext/mysql functions to the new mysqli extension be careful not to also port over the bad practices of the old extension as well (such as using the old SQL string concatenation and escaping techniques ext/mysql offered). Instead take advantage of MySQLi prepared statements and parameterized queries.

    What I do want to direct your attention to are the benefits of using the newer APIs to interface with your MySQL database (namely PDO and MySQLi).

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

Sidebar

Related Questions

I have a few scripts that use the function pop-to-buffer a lot. It used
I have a function that is used to creating a directory. It uses CreateDirectoryA()
I have one javascript function that used to display the menu and content in
I have used sendinput() function and windows keyboard hooks to develop a custom keyboard
I have used this function to convert string to bits. def a2bits(chars): return bin(reduce(lambda
I have a function that I have used a bunch of times in various
I have a function in java script, that I used it to take the
Right now I have a function, in a class that is used to listen
I have a problem when call applet method from javascript.. I used this function
I have used the crypt function in c to encrypt the given string. I

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.