0
<?php // sqltest.php
$db_hostname='localhost';
$db_database='book';
$db_username='';
$db_password='';

$db_server = mysqli_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysqli_error());
mysqli_select_db($db_server,$db_database )
or die("Unable to select database: " . mysqli_error($db_server));

I am using localhost:8080 and localhost:8080/phpMyAdmin to access the whole thing. Now I have code which runs like you see above and getting error message unable to select database. What should I do to remove the error.

2
  • You have to set username and password Commented May 26, 2016 at 13:56
  • 2
    @EugeneSmith Do you expect the OP to put the username and password on a public place like Stack Overflow? Commented May 26, 2016 at 13:59

1 Answer 1

2

You don't do mysql_select_db. You do this way:

$db_server = mysqli_connect($db_hostname, $db_username, $db_password, $db_database);

See the manual:

Note: This function should only be used to change the default database for the connection. You can select the default database with 4th parameter in mysqli_connect().

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.