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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:07:48+00:00 2026-05-23T08:07:48+00:00

Are there any reasons why this might be the case? Here’s the code: $dbc

  • 0

Are there any reasons why this might be the case?

Here’s the code:

$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
echo $dbc;
if(!$dbc){
die('could not open a connection'.mysqli_connect_errno() . mysqli_connect_error());
}

Again, if I replace mysqli with mysql I get a returned dbc resource id (I assume that’s good). I would like to use mysqli as I hear it’s much better/faster. Right now I’m getting error code 2003.

  • 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-23T08:07:49+00:00Added an answer on May 23, 2026 at 8:07 am

    mysql_connect() and mysqli_connect() use two different default ports from the php.ini file. I wouldn’t guess that these would be different than the standard default 3306, but worth a check or try adding the path to the host url.

    mysqli_connect:

    mysqli mysqli_connect ( … int $port = ini_get(“mysqli.default_port“) … )

    mysql_connect:

    If the PHP directive mysql.default_host is undefined (default), then the default value is ‘localhost:3306’. In SQL safe mode, this parameter is ignored and value ‘localhost:3306’ is always used.

    Edit: I was wrong because I didn’t read the manual page far enough.


    I think your connection is fine, but you wouldn’t want to check the object it returns as you have above. You’d want to use mysqli_connect_errno(). Below is the example from PHP.net.

    $mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
    
    if (mysqli_connect_error()) {
        die('Connect Error (' . mysqli_connect_errno() . ') '
                . mysqli_connect_error());
    }
    

    Note:
    OO syntax only: If a connection
    fails an object is still returned. To
    check if the connection failed then
    use either the mysqli_connect_error()
    function or the mysqli->connect_error
    property as in the preceding examples.

    Source

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

Sidebar

Related Questions

I read this answer and its comments and I'm curious: Are there any reasons
Are there any good reasons for why you would include JavaScript like this: <script
Is there any reason why this shouldn't work? [PseudoCode] main() { for (int i
Is there any reason something like this would not work? This is the logic
Is there any reason why XML such as this : <person> <firstname>Joe</firstname> <lastname>Plumber</lastname> </person>
Is there any reason to do use block initialization, like this: x = Observer.new
I'm trying to do this, and failing. Is there any reason why it wouldn't
Are there any reasons why the simulator will display UIImageViews properly, but incorrectly on
Is there any reasons why PHP's json_encode function does not escape all JSON control
Are there any good reasons not to use \u0000 as a delimiter within a

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.