EternalSorrow Posted June 15, 2012 Share Posted June 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/ Share on other sites More sharing options...
insidus Posted June 15, 2012 Share Posted June 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354032 Share on other sites More sharing options...
EternalSorrow Posted June 15, 2012 Author Share Posted June 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354034 Share on other sites More sharing options...
insidus Posted June 15, 2012 Share Posted June 15, 2012 Try logging in with the user you in phpmyadmin, then run a simple query on the database, if that succedes then it is the script. Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354089 Share on other sites More sharing options...
EternalSorrow Posted June 15, 2012 Author Share Posted June 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354140 Share on other sites More sharing options...
PFMaBiSmAd Posted June 15, 2012 Share Posted June 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354142 Share on other sites More sharing options...
EternalSorrow Posted June 16, 2012 Author Share Posted June 16, 2012 I've never actually dealt with any host which didn't use 'localhost' for the hostname. My new hosting service doesn't appear to be any different than the previous host. I also use 'localhost' for all other connections to my other databases. Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354284 Share on other sites More sharing options...
fenway Posted June 16, 2012 Share Posted June 16, 2012 As root, type "SHOW GRANTS for 'user_name'@'locahost'", and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354474 Share on other sites More sharing options...
EternalSorrow Posted June 18, 2012 Author Share Posted June 18, 2012 I'm sorry if I seem slow, but I have no idea what to implement what you just suggested. The Google has also failed me in this effort to decipher your code-speak. Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354747 Share on other sites More sharing options...
Pikachu2000 Posted June 18, 2012 Share Posted June 18, 2012 Do you have access to the db via command line or phpMyAdmin or the like? Quote Link to comment https://forums.phpfreaks.com/topic/264211-not-connecting-to-database/#findComment-1354748 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.