Jump to content

Not Connecting to Database


EternalSorrow

Recommended Posts

I changed hosts a few months back and was never able to get a third-party script to work properly after the move.  I tried changing the script to adapt to what I thought were the problems, but this error message still pops up:

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user_name'@'localhost' (using password: YES) in /home/cirque8/public_html/seras/fanlisting/backend/install.php on line 47
Cannot connect to the MySQL server: Access denied for user 'user_name'@'localhost' (using password: YES)

 

I've tried changing the offending line, which starts at the $db_link:

 

<?php
/*****************************************************************************
Enthusiast: Fanlisting Management System
Copyright (c) by Angela Sabas
http://scripts.indisguise.org

******************************************************************************/
require_once( 'header.inc.php' );
require_once( 'config.inc.php' );
?>

<p class="location">Enthusiast > Create database table</p>

<?php

if( isset( $_GET["done"] ) ) {
$query = 'CREATE TABLE `' . $db_table . '` (' .
	'`email` varchar(64) NOT NULL default \'\', ' .
	'`name` varchar(128) NOT NULL default \'\', ';
if( !isset( $disable_country ) || !$disable_country )
	$query .= '`country` varchar(128) NOT NULL default \'\', ';
$query .= '`url` varchar(254) default NULL, ';
if( $additional_field ) {
	foreach( $additional_field_names as $field ) {
		$query .= '`' . $field . '` varchar(255) ' .
			'default NULL, ';
		}
	}
$query .= '`pending` tinyint(1) NOT NULL default \'0\', ' .
	'`password` varchar(128) NOT NULL default \'\', ' .
	'`showemail` tinyint(1) NOT NULL default \'1\', ' .
	'`showurl` tinyint(1) NOT NULL default \'1\', ' .
	'`added` date default NULL, ' .
	'PRIMARY KEY  (`email`) ' .
	') TYPE=MyISAM;';

$db_link = mysql_connect( $db_server, $db_user, $db_password )
	or die( 'Cannot connect to the MySQL server: ' .
		mysql_error() );
mysql_select_db( $db_database )
	or die( 'Cannot select database: ' . mysql_error() );
$result = mysql_query( $query )
	or die( 'Cannot execute query: ' . mysql_error() );

if( $result ) {
	echo '<p><b>Database table created successfully.</b></p>';
	}
else {
	echo '<p><b>There was an error creating the table.' .
		' Please try again.</b></p>';
	}

// check if affiliates are enabled
if( isset( $enable_affiliates ) && $enable_affiliates ) {

	// create affiliates table
	$query = 'CREATE TABLE `' . $db_table . '_affiliates` (' .
		'`affiliateid` int(5) NOT NULL auto_increment, ' .
		'`url` varchar(254) NOT NULL default \'\', ' .
		'`title` varchar(254) NOT NULL default \'\', ' .
		'`imagepath` varchar(254) default NULL, ' .
		'`width` int(3) default NULL, ' .
		'`height` int(3) default NULL, ' .
		'PRIMARY KEY  (`affiliateid`) ' .
		') TYPE=MyISAM AUTO_INCREMENT=1 ;';

	$result = mysql_query( $query )
		or die( 'Cannot execute query: ' . mysql_error() );

	if( $result ) {
	echo '<p><b>Affiliates database table created ' .
		'successfully.</b></p>';
		}
	else {
		echo '<p><b>There was an error creating the ' .
		'affiliates table. Please try again.</b></p>';
		}
	}

echo '<p>Delete the install.php file after creating the tables ' .
	'to ensure your security.</p>';

}
else {
?>

<p>
You can automatically create your database table via this page.<br />
<b>Please make sure that you have edited your config.inc.php file
before<br />
doing this. Refer to the table below.</b>
</p>

<p><table>

<tr><td>
$db_server
</td><td>
Usually "localhost", please refer to your host if otherwise.
</td></tr>

<tr><td>
$db_user
</td><td>
Username to connect to the database
</td></tr>

<tr><td>
$db_password
</td><td>
Password to connect to the database
</td></tr>

<tr><td>
$db_database
</td><td>
Database name the FL table will be created in;<br />
MUST ALREADY EXIST before this script is continued<br />
(refer to your host on how to create a database)
</td></tr>

<tr><td>
$db_table
</td><td>
The table name for your database;<br />
e.g., if your <?= $listing_type ?> is for computers,<br />
it would be "computers".
</td></tr>

<tr><td>
$additional_field
</td><td>
If you want an extra, customized field for your FL,<br />
you should set this to "true".
</td></tr>

<tr><td>
$additional_field_names[]
</td><td>
Create a new line with each additional field name (no spaces), i.e.:
<br /><i>$additional_field_names[] = 'character';<br />
$additional_field_names[] = 'scene';</i>
</td></tr>

</table></p>

<br />

<p><b>If you're done editing your config.inc.php file, click the
button below.</b></p>

<form action="<?= $_SERVER["PHP_SELF"] ?>" method="get">
<input type="hidden" name="done" />
<input type="submit" value="Create my FL Table" />
</form>

<?php
}
require_once( 'footer.inc.php' );
?>

 

I still can't figure out exactly how it can't connect to the database even when I replace all the $db_server, $db_user, and $db_password fields to what they actually are.  Anyone have any ideas what the problem could be?  Thanks in advance for any assistance.

Link to comment
Share on other sites

The user doesn't exists in MySql, if you have Phpmyadmin installed, go to Privileges and make sure the user 'user_name' actually exists, has the CORRECT password, and have access to the database your trying to query. the error is Access denied for user 'user_name'@'localhost', which means you have an error with the user trying to connect.. either it doesn't exists, or the credentials are wrong.

 

/insidus

Link to comment
Share on other sites

I realize the problem is with the user trying to connect, and I've tried using various user names with all privileges granted and they all receive the same message.  This, along with having the correct password as the error message says, makes me think the problem is not with the user_name but with the script.

Link to comment
Share on other sites

I found that indeed the user I was using appears to be incompatible with the database (not sure why, with all permissions), and so I changed the username to one which was accepted by the database (and tested using a simple query, just to make sure).

 

Unfortunately, there's still a problem.  Here's the new error message (which I had received using this username previously):

 

Cannot select database: Access denied for user 'user_name'@'localhost' to database 'fanlisting'

 

Next step, bash head on keyboard.

Link to comment
Share on other sites

The database hostname on hosting is rarely localhost. It is usually something like - mysqln.yourwebhost.com

 

The database hostname to use for your scripts is usually displayed somewhere on the control panel where you create databases/tables/users/passwords.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.