Skip to main content

Database error after moving website?



I just moved my website from a test domain to the actual domain and I changed the DB info in the PHP script, but I'm still getting an error even though I triple-checked that I have the correct database, host, username and password. Am I missing something? This is the code I use to connect. The database info is definitely correct.







$dbhost = "localhost";

$dbuser = "username";

$dbpass = "password";



function dbConnect($db='dbname') {

global $dbhost, $dbuser, $dbpass;



$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)

or die('Database problem.');



if ($db!='' and !@mysql_select_db($db))

die('Database not available at the moment. Please try again in a couple of minutes.');



return $dbcnx;

}







And then I call the function dbConnect('dbname') from the script. The error I get is the second error from the code above, "Database not available at the moment. Please try again in a couple of minutes.".





Can anyone see something I'm missing here?





EDIT:





The actual MySQL error is:







Access denied for user 'username'@'localhost' to database 'dbname'




Comments

  1. Sounds like it could be a permissions problem.

    Try logging in to mysql and running:

    grant all on <your db name>.* to <your user>@localhost identified by '<your password>';
    flush privileges.

    ReplyDelete
  2. If you take the error suppression (@) from your code it may give you more of a clue

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.