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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:52:49+00:00 2026-06-14T18:52:49+00:00

I am very new to php, and am sorry if this question turns out

  • 0

I am very new to php, and am sorry if this question turns out to be too vague, but if there is any other information that you need from me let me know.

Anyway, basically what my problem is I have some simple php code that should call die() if it can’t connect to the xampp server I have set up, however, even if I put in invalid info for the server or user it prints Successful. I really don’t know where to go with this, so if anyone has any suggestions that would be great.

<?php

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';



if ( !mysql_connect($dbhost, $dbuser, $dbpass) )
{
    die(mysql_error());
} 
else
    echo 'Succesful';

?>

Ok for some reason it was just not working with the root user, so I created a new user who required a password and apparently that connected like it was supposed to. Thanks everyone for the answers.

  • 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-14T18:52:51+00:00Added an answer on June 14, 2026 at 6:52 pm

    I have found that when trying to connect php to an xampp server there are usually only a few things that could cause the issue you are having.

    1. mySQL service is not running
    2. no specific database is selected to try to access
    3. user does not exist in phpmyadmin.
    

    When you pick a user to connect php to mySQL with you should always make sure that a password is set, that is usually the thing people miss. You can use root if you create another instance of it in the user list and require a password, or you can add a password to the root user already in the list, but the best option is to create a new custom user that only has access to the database you want to access with your php and make sure it has a password required. (make sure any user you use can connect with localhost; root can by default and I think most newly created users can as well).

    Below is the php I use for websites I design that need php to access a DB.

    <?php
    // This configures the variables for database access
    $dbhost = 'localhost';
    $dbuser = '????';
    $dbpass = '????';
    $dbname = '????';
    
    
    // This will connect to the server and then the correct database
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    mysql_select_db($dbname);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this question seems obvious for everyone, but I am very new to
I am very new to PHP and MySql. Is there any method by which
Sorry, I'm very new to PHP, and I can't find anything about this in
There is probably a very simple fix to this, but i'm all new with
I know the title isn't very clear. I'm new to PHP, so there might
First, sorry for the stupid question, but I was reading an article in php.net
Sorry if this is wrong or confusing I am very new to using classes
I'm very new to PHP and I got this error (I use Code Igniter).
Sorry about the length of this question. I'm new to Java and I've come
I am very sorry. This is follow up for my question here : Why

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.