0

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?

Edited by dyea.marcello

4
Contributors
9
Replies
34
Views
3 Years
Discussion Span
Last Post by diafol
0

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.

0

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.

0

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

0
<?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

1

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

0

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

0

*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:

0

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?

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.