Meet The Author

Main Uddin is one of the pioneer blogger cum e-marketer from North East India(Assam).He is also a Skilled web Developer and regular columnist for various news portals around the globe.Read More

author

Instant Fixing the Error Establishing a Database Connection in WordPress

Leave a Comment
If you have been surfing the web for a while, you have at least seen this error a few times. Error Establishing a Database Connection is one of those curses that could be caused by many reasons. As a WordPress beginner, this could be awfully frustrating specially when it happened on its own without you changing anything. We ran into this issue yesterday on our own site. It took a little over 20 minutes to detect and fix the problem. While doing the research to find possible causes, we realized that there was no good article that covered everything. In this article, we will show you how to fix the error establishing a database connection in WordPress by compiling a list of solutions all in one place.
Note: Before you make any database changes, make sure you have sufficient backups.

Why do you get this error?

Well in short, you are getting this error because WordPress is unable to establish a database connection. Now the reason why WordPress is unable to establish a database connection can vary. It could be that your database login credentials are wrong or have been changed. It could be that your database server is unresponsive. It could be that your database has been corrupted. In our experience, majority of the times this error happens because of some sort of server error however there could be other factors as well. Lets take a look at how to go about troubleshooting this problem.

Does the problem occur for /wp-admin/ as well?

First thing you should do is to make sure that you are getting the same error on both the front-end of the site, and the back-end of the site (wp-admin). If the error message is the same on both pages “Error establishing a database connection”, then proceed onto the next step. If you are getting a different error on the wp-admin for instance something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database.
You can do this by adding the following line in your wp-config.php file. Add it just before ‘That’s all, stop editing! Happy blogging’ line wp-config.php.
1define('WP_ALLOW_REPAIR', true);
Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php
Repair database in WordPress
Remember, the user does not need to be logged in to access this functionality when this define is set. This is because its main intent is to repair a corrupted database, Users can often not login when the database is corrupt. So once you are done repairing and optimizing your database, make sure to remove this from your wp-config.php.
If this repair did not fix the problem, or you are having trouble running the repair then continue reading this article as you might find another solution to work.

Checking the WP-Config file

WP-Config.php is probably the single most important file in your entire WordPress installation. This is where you specify the details for WordPress to connect your database. If you changed your root password, or the database user password, then you will need to change this file as well. First thing you should always check is if everything in your wp-config.php file is the same.
1define('DB_NAME''database-name');
2define('DB_USER''database-username');
3define('DB_PASSWORD''database-password');
4define('DB_HOST''localhost');
Remember your DB_Host value might not always be localhost. Depending on the host, it will be different. For popular hosts like HostGator, BlueHost, Site5, it is localhost. You can find other host values here.
Some folks suggested that they fixed their problem by replacing localhost with the IP. It is common to see this sort of issue when running WordPress on a local server environment. For example on MAMP, the DB_Host value when changed to the IP may seem to work.
1define('DB_HOST''127.0.0.1:8889');
IP’s will vary for online web hosting services.
If everything in this file is correct (make sure you check for typos), then it is fair to say that there is something wrong on the server end.

Check your Web Host (MySQL Server)

Often you will notice this Error establishing database connection when your site gets swarmed with a lot of traffic. Basically, your host server just cannot handle the load (specially when you are on shared hosting). Your site will get really slow and for some users even output the error. So the best thing you should do is get on the phone or livechat with your hosting provider and ask them if your MySQL server is responsive.
For those users who want to test if MySQL server is running yourself, you can do a few things. Test other sites on the same server to see if they are having the issue. If they are also getting the same error, then most definitely there is something wrong with your MySQL server. If you do not have any other site on this same hosting account simply go to your cPanel and try to access phpMyAdmin and connect the database. If you can connect, then we need to verify if your database user has sufficient permission. Create a new file called testconnection.php and paste the following code in it:
1<?php
2$link = mysql_connect('localhost''root''password');
3if (!$link) {
4die('Could not connect: ' . mysql_error());
5}
6echo 'Connected successfully';
7mysql_close($link);
8?>
Make sure to replace the username and password. If the connected successfully, then it means that your user has sufficient permission, and there is something else that is wrong. Go back to your wp-config file to make sure that everything there is correct (re-scan for typos).
If you cannot connect to the database by going to phpMyAdmin, then you know it is something with your server. It does not necessarily means that your MySQL server is down. It could mean that your user does not have sufficient permission.
In our case, our MySQL server was running. All other sites on the servers were working fine except for WPBeginner. When we tried going to our phpMyAdmin, we ended up getting the error:
#1045 – Access denied for user ‘foo’@’%’ (using password: YES)
We got on the phone with HostGator and their support quickly found the problem. Somehow our user’s permissions were reset. Not sure how that happened, but apparently that was the reason. They went back in and restore the permissions and we were able to get the site back live.
So if you get the access denied error in either connecting to your phpMyAdmin or through test connection.php results, then you should contact your host right away to get them to fix it.

Solutions that Worked for Others

It is important to note, that these may not work for you. Use at your own risk and make sure that you have sufficient backups if anything goes wrong.
Deepak Mittal said that his client was getting the error that database needs to be repaired. Even after repairing the database, the error did not go away. He tried various things and at the end, the issue was the site url. Apparently that was changed which caused the error to persist. He ran the SQL query by going to phpMyAdmin:
1UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'
Make sure to replace YOUR_SITE_URL with the actual url example: http://www.wpbeginner.com. The wp_options will be different if you have changed the default WordPress database prefix.
This seemed to fix the issue for him and few others that commented on his post as well.
Sachinum suggested that he was able to connect the database with testconnection.php, so he changed the wp-config.php user to the root user. WordPress started to work perfectly fine. Then he reverted the settings back to the database-user, and it continued to work. He could not figure out what was wrong, but concluded that it was a typo.
Cutewonders suggested that they removed the content of active_plugins in wp_options table and edited the contents of recently_edited. Basically that seemed to fix the problem. 
We read on numerous sources that users simply uploaded a fresh copy of WordPress and it fixed the error.
This is a really frustrating error. What have you tried that seemed to work for you? We would be happy to expand on this resource, so others do not have to waste as much time finding a solution.
Read More

Why Do Pro Bloggers Choose Adx with Comparison of Google Adsense?

Leave a Comment
Google AdSense is a plug-and-play solution for publishers to quickly make money off of web and mobile assets. It’s also a great way to monetize a niche blog, for example. But as your traffic quality and reputation improve, you may be invited to join the big boys club – Google DoubleClick Ad Exchange. Also known as AdX in short.

The question you are probably asking yourself is this: Which will bring me more revenues? Some sources claim publishers have seen a 30% percent increase in overall ad revenues with AdX instead of AdSense.


But before you rush to fill in the fields of a Google signup form, we’ve done the heavy lifting for you and checked and studied the issue.

So, what’s the answer to this big life altering question? The answer, as it often is, is: it’s different for every publisher.

Not what you were hoping to hear? Sorry. If you’re a faithful reader of this blog then you know by now…no quick wins.

But which ad inventory sales option is right for me you ask?

Ok. Fine. Read on and we’ll figure it out together.

Key Differences Between AdSense and AdX

If you’re a little lost as to the difference between Google AdSense and AdX, don’t worry. You’re not alone. Google lists the differences between the two in a comparison table, but as Google tends to do frequently, they leave it open for interpretation.

In a nutshell, AdSense is an automatic smooth rider and AdX is your stick shift manual speed racer. One will get you from point A to point B, while the other offers more control for better overall yield.

Your solution of choice might drive your revenues where you want them, or it could break in the middle of the road and leave you hitchhiking for user donations. Or worse. That’s why we want to help you choose wisely.

1. Who Sets The Price and Pays
AdSense is the publisher side of AdWords, an advertising network owned by Google. AdSense includes search ads on Google Search, ads in Google products (like Gmail, Blogspot and YouTube) as well as GDN, the Google display network – that’s where you offer your ad space.

With AdSense, Google basically buys all the inventory offered to it by publishers, pricing it according to the bids set by advertisers for each ad, campaign and keyword.

From the moment you paste that ad unit code on your site, your AdSense units will never be empty (unless you have a technical issue affecting your AdSense setup).

But your RPM will depend almost entirely on Google’s contextual ad serving algorithm and retargeting ads. No matter how hard you optimize your AdSense metrics, you won’t be able to set a floor price for ads served on your site.

So if you’ve hit a revenue ceiling with AdSense (after trying all our many optimization tips) – you might want to consider driving stick for a while. Who knows? You might actually like it.

On the other hand, Google DoubleClick Ad Exchange is a programmatic RTB exchange with many players, including brands, agencies, arbitrage buyers and sellers, as well as different advertising networks (including AdSense!).

You get more demand sources for your inventory and can control who gets to bid on it.


With AdX you set the floor prices for your inventory and buyers compete in a lively auction on who gets to display that ad on your page. If you’re getting dollar eyes like a cartoon character now, we’re not surprised.

At first, this may seem like a golden opportunity to increase your revenue fast, but it’s not as simple as that.

If your floor prices are too high and your inventory is not as attractive as that of your competitors – you might end up with lower earnings than you would have had by using AdSense alone.

2. Who Needs What and When
According to Google, the main difference between the two monetization tools is the target audience. While AdSense is a kind of one-stop-shop for ad-based web content monetization, AdX is aimed at publishers who also sell inventory directly, as well as established brands and eCommerce sites with a lot of quality traffic.

That’s not all. AdX also allows broader blocking options to prevent inventory cannibalization, and of course, to stop competing brands from advertising on your site. No one wants to discover their competitor is stealing their hard-earned quality traffic from under their nose.

As you may have realized by this point, AdX requires a lot more maintenance and time investment than AdSense in order to be really profitable. There are quite a few new terms, techniques, and variables to learn if you want to adopt Google’s ad exchange (or any other ad exchange).
AdX lets you build advanced rule-sets and flows for specific advertisers, use direct deals routed out of the exchange and dynamically allocate inventory and pricing on your ad space and projected traffic.

For example, if you see that an advertiser has targeted you on AdX and you’re getting a lot of impressions for their ads? You can contact them directly (kinda) and offer them more for a higher price. Something you cannot do with AdSense.

Why would they agree to pay more? Because you can guarantee that they get the targeting they want with the placements they want, and whatever other criteria matching they request.

Bottom line, they’re guaranteed a quality ad impression. Next in your ad stack are, what’s called, preferred advertisers, and AdX can compete with them using dynamic allocation.
Yes, it’s pretty complicated and takes time and expertise to be effective. So if you don’t have direct advertisers, relationships with ad networks and exchanges, and you don’t have the knowledge, time or manpower to dedicate to AdX optimization then it really isn’t for you. You’ll actually find yourself making less money from it. 
3. Ad Units – More or Less?
One of the main differences everyone seems to talk about is the number of ad units in each of the monetization tools offered by Google to publishers.

In short, AdSense permits up to three ad units per page, while AdX allows up to five ad slots. In theory, you can boost RPMs significantly by increasing the number of ads on each page. But that’s theory. Reality check, you should be able to optimize your RPM with 3 ad units while maximizing your RPM.

Let’s dig a bit deeper into the differences to find the facts.

The first thing you must remember is that users still hate ads. Don’t overegg your ad pudding or you’ll find your audience arming themselves with ad blockers or just abandoning you altogether.

So having more ads won’t necessarily boost your RPMs and it definitely won’t improve your most important metric – RPV (revenue per visitor).

But if you have long content pages having more ad units per page may save you having to use “floating” ads.

The limit for AdSense ads per page remains the same even if you use AdX. What this means is that if you use the maximum 5 ad units per page (on desktop), but only 3 can be filled by AdSense. The rest will have to come from other buyers in the exchange and guaranteed or preferred advertisers.
4. Revenue Share
Google is pretty straightforward about how much it’s making off every click on AdSense. Publishers (that’s us) get 68 percent of what the advertisers pay for every click with display ads. And just 51 percent with AdSense for search.

With AdX it’s different. Don’t tell anyone we told you this but if you have a large enough website that offers great content then you may be able to negotiate your revenue share with Google. That’s probably why you hear rumors that AdX will offer you a higher rev share.

It’s only true if you have a very large website and a dedicated Google account manager.

Although offering ad space on AdX is time consuming and complex, this difference in revenues can be very significant with large websites with a lot of traffic and clicks.
5. CPM vs CPC
In AdSense, you get paid for every click on an ad. Kinda. What you’re actually getting is a share of the revenue from Google, and Google gets paid in CPM (cost per millenia – 1,000 impressions). They later translate that into CPC.

With AdX it’s pretty much the same. Bids and floor prices are set in CPMs, so you get paid for impressions rather than clicks, even if the ads you display are fallback AdSense ads, meaning that AdSense ads only get displayed after more lucrative ads like ones sold directly.

This doesn’t mean you shouldn’t aim for a high CTR. Advertisers aren’t all stupid, and if they see that traffic from your site doesn’t convert – they’ll take their budget elsewhere.
6. Advertiser Relationships
Advertisers who get good performance on your page with AdX, will want more of it. What you want to aim for is direct sales to brands and advertisers yearning to appear before the eyes of your reader audience.

You can offer them your well performing ad placements and units for a premium, and sell the remnant inventory through AdX and other ad exchanges. That way you can attract new advertisers to your online property, and upsell premium placement to advertisers who’ve bid on your remnant inventory and got good results.
7. DoubleClick for Publishers (DFP)
If you’ve been researching AdX, you’ve probably come across Google’s ad server for publishers – DoubleClick for publishers. With DFP, you can let AdX compete against other ad networks, and divide the traffic between demand sources in the most profitable way for you.

It’s a management platform for publishers with multiple demand sources for ad space, and if you are one or trying to become one – you should familiarize yourself with DFP.
DFP is a free cloud service, but its implementation can be challenging and not cost effective for small blogs without a dedicated ad broker.
The verdict

There are quite a few advantages to AdX over AdSense, but your potential to increase revenue by moving to AdX depends mostly on your needs, size, your advertisers, capacity, and technical expertise. And before all that, it also depends on being accepted to AdX by Google.

That alone is enough to be the bane of your online existence. Is your site right for AdX or is AdSense the best Google can offer you for web traffic monetization? If you have direct advertisers making it worth your while to spend the time on constantly optimizing AdX – Yes.

If not, you’ll probably end up with low fill rates (empty ad units) and make less money than you would have with AdSense.
Read More
Next PostNewer Posts Previous PostOlder Posts Home