Reputation: 1
<?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.
Upvotes: 0
Views: 996
Reputation: 167182
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()
.
Upvotes: 2