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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:56:23+00:00 2026-06-12T09:56:23+00:00

I am establishing a database connection in php using the function $DBConn = mysql_connect

  • 0

I am establishing a database connection in php using the function

$DBConn = mysql_connect ("localhost" , "testuser" , "test123")

At the time of releasing the connection I am using

if( is_resource($DBConn) )

to check whether the connection is currently set or not. I want to know is it efficient to do this or I should check the connection like this

if( $DBConn )

I want to know prod and cons of using both the statements.

  • 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-12T09:56:24+00:00Added an answer on June 12, 2026 at 9:56 am

    First of all, you should no longer be using mysql_xxx functions; there are many articles out there that discuss the benefits of having prepared statements, etc. with PDO / mysqli.

    By looking at the manual, it states that it returns a link identifier or false on failure. You shouldn’t make assumptions as to what exactly this identifier is, it’s usually a resource but it may as well be an object or integer. I would simply negate the easier condition:

    if (false !== $DBConn) {
        // do something with the database
    }
    

    Or, alternatively:

    if (false === $DBConn) {
        throw new Exception("Could not connect to database");
    }
    // do something with the database
    

    Edit

    Using if ($DBConn) { ... } is okay as well, because it’s basically the opposite of 0, false, null, “” and empty array.

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

Sidebar

Related Questions

When establishing a connection to a database using PDO, should the PDO attribute PDO::ATTR_PERSISTENT
I am establishing a connection to a mssql server database in asp using the
I have a python script called mythicalPythonBindings.py. It outputs something like Establishing database connection
I am getting the error: error establishing a database connection after moving my wordpress
My Wordpress website got a error establishing connection to database massage. My host informed
Iam building a cloud application with google apps.While establishing a connection with cloud database
In PDO, a connection can be made persistent using the PDO::ATTR_PERSISTENT attribute. According to
I am considering establishing an encrypted connection from a .NET app toward a remote
I've been trying to connect Excel to online mysql database. Im using 5.1 DSN
I am using OOP MySQLi to connect to my database. I have checked my

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.