I am trying to display a list of my book However I can't select the database:

this is a piece of my code:

<?php
$mysql_hostname = "localhost";
$mysql_user = "";
$mysql_password = "";
$mysql_database = "mag_rocket";
$prefix = "";
$bd = mysql_connect($mysql_hostname) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?>

I am substituting some things here in this example but all my credentials are correct including my db server username, password and forum db name. So what is the problem?

Recommended Answers

If you change die("Could not connect database"); with:

 die(mysql_error());

You should get the error code, if this does not help then paste the error here.

Jump to Post

Sorry I was actually referring to the second die function, try:

<?php

$mysql_hostname = "localhost";
$mysql_user = "";
$mysql_password = "";
$mysql_database = "mag_rocket";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db($mysql_database, $bd) or die(mysql_error());

By the way, the connect string was …

Jump to Post

For this last error, it's pretty self explanatory. Are you sure you are supplying the correct credentials to connect to the target DB?

Jump to Post

All 9 Replies

If you change die("Could not connect database"); with:

 die(mysql_error());

You should get the error code, if this does not help then paste the error here.

still cannot display the database.

*Could not select database

Sorry I was actually referring to the second die function, try:

<?php

$mysql_hostname = "localhost";
$mysql_user = "";
$mysql_password = "";
$mysql_database = "mag_rocket";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db($mysql_database, $bd) or die(mysql_error());

By the way, the connect string was lacking of second and third parameters, i.e. username and password.

not successful.

*Notice: Use of undefined constant mysql_error - assumed 'mysql_error' in C:\xampp\htdocs\sites\bookstore\connection.php on line 8
mysql_error

<?php
$mysql_hostname = "localhost";
$mysql_user = "";
$mysql_password = "";
$mysql_database = "mag_rocket";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db($mysql_database, $bd) or die(mysql_error());

*Notice: Access denied for user ''@'localhost' to database 'mag_rocket

For this last error, it's pretty self explanatory. Are you sure you are supplying the correct credentials to connect to the target DB?

All my credentials are correct including my db server username, password and forum db name.

*Notice: Access denied for user ''@'localhost' to database 'mag_rocket

As JorgeM said, the error means that the user you're providing does not own privileges to the database you're trying to connect. User and password are correct, but the admin has to change the permissions settings for your username. Open a mysql shell with the mysql admin account and use:

GRANT ALL PRIVILEGES ON mag_rocket.* TO 'username_here'@'localhost';

Check this for more information:

Member Avatar

OK, you're using xampp on your local machine. The default conenction details AFAIK are:

host: 'localhost'
user: 'root'
p/w: ''

Otherwise check to see if XAMPP is running mysql...

d7b1b5ceea196abbe0299cf48c541a6a

Also I noticed a couple of years ago Skype played havoc with my xampp mysql install. Got an old version?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.