0

"Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\appraisal\database.php on line 5 No database selected"

Why does it show most of the time? But when I refresh the page by entering F5, the error will be gone and will show the output correctly. This doesn't really affects the system but it is quite bothering when our users see the error.

I have the codes here.

<?php
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db('db_appraisal');
?>

Hoping for your response. Thanks!

1
  • 2
    Please don't add 'solved' to question titles. Commented Oct 23, 2014 at 11:21

1 Answer 1

2

Try adding the $conn parameter to the mysql_select_db function call

<?php
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db('db_appraisal', $conn);
?>

Link to The Manual

If you are writing new PHP code you should really not be using the mysql_* extension as it has been deprecated i.e. it will be removed from PHP sometime soon.

Use either the mysqli_* extension or the PDO one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.