Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLogan R
22,989 PointsWordPress Migration [Error establishing a database connection]
Hey guys! So I transfered from Cpanel to a VPS and I had 1 WP and 1 Drupal site to move. The Drupal was pretty fast and easy to do.
The WordPress site is giving trouble. I copied the files and put them in the same place they were before. (say it was at mydomain.com/wp, it's still at mydomain.com/wp) and I changed the DB configs in the wp-config.php and it's still just giving a giant h1 Error establishing a database connection when I go to the site.
Side note: I'm accessing it from localhost/wp, idk if that changes anything. I tested the username and password of the SQL user and it worked so I know that's not the problem and I did a side by side comparison of both the table names and table sizes and they were the same too.
Anyone have any suggestions about what could of gone wrong because Google was no help at all. I tried going to wp-admin/repair and that didn't work either, it just produced the same error message: Error establishing a database connection.
2 Answers
Chelsey Beck
1,905 PointsTry making a sample.php file on the web server and seeing if you can get a connection.
<?php $mysqli = new mysqli("localhost", "user", "password", "database"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } echo $mysqli->host_info . "\n"; ?>
Chelsey Beck
1,905 PointsAwesome! That's what I was aiming for ; )
Chelsey Beck
1,905 PointsMake sure to add that code to future connections so that it kicks back an error.
Logan R
22,989 PointsLogan R
22,989 PointsThank you very much :D
This produced an error and I figured it out! I added an extra letter to the database name lol. It's now working!