Tag Archives: technology

How to fix WP Error Establishing a Database Connection

The Error Establishing a Database Connection error is a very common issue on WordPress. This issue is caused by a connection failure between the WordPress CMS and the SQL database. Here is a simple guide to fix the problem.

A typical error message displayed on site.
A typical error message displayed on site.

Finding the cause

This can be caused by several issues. If you are getting the same error, “Error Establishing a Database Connection”, on the main front page as well as the wp-admin section, then the problem is most likely the credentials. This is the most common reason for this issue. However, if the error message on the wp-admin section is different from that of the front page, then it is most likely caused by a database corruption. I will explain several methods to fix the problem.

Fix wp-config file

From the back-end of your server, open the wp-config.php file in an editor. If you are using cPanel, then you can do this from file manager. If you have your own server, you can access the file either using FTP or remote desktop connection. Check if the following parameters are setup properly in wp-config.php.

define('DB_NAME', 'database_name');
define('DB_USER', 'database_username');
define('DB_PASSWORD', 'database_password');
define('DB_HOST', 'localhost');

The information in wp-config.php file should match the corresponding current database user account. These accounts should be listed under under MySQL Databases section of your server. On cPanel it is located under Databases sub section.

MySQL in cPanel
MySQL in cPanel

Typically the database name is composed of your username_databaseName. All the current databases and users will be listed within the MySQL admin page (example shown below).

List of current databases and users.
List of current databases and users.

If the exact same username appears in the MySQL current list as it is in the wp-config, then it may be the password. You cannot check what password is used for each user account. But you can change the current password. To do that, under MySQL Users –> Add New User, enter the current username, Then enter a password you prefer. This will update the existing account.

Updating the password for a user.
Updating the password for a user.

Fix corrupted database

As mention above, if the error message on the wp-admin section is different from “Error Establishing a Database Connection”, then it is caused by a database corruption. WordPress comes with a built in repair method in repair.php. First add the following to the top of wp-config.php file.

define('WP_ALLOW_REPAIR', true);

Then run the following file located at, http://domain.com/wp-admin/maint/repair.php. It will provide you with “Repair Database” and “Repair and Optimize Database” options. Choose either one to fix the issue. Once the repair is successful (or not), please delete the WP_ALLOW_REPAIR from the wp-config.php file. With the code in place, anyone one access the repair page without administrative account.

Connection to database

This can be tested by running a simple PHP script. Create a PHP file with the following code such as test.php.

$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
echo 'Connected successfully';

If it provide a feedback with a successful connection, then your database is working. If not, either the database is corrupted or the sever files are damaged. Contact your hosting company for help. If it is your own server, then your best hope is to replace the MySQL files with available backup.

Building a website

I do not think you need an explanation on what is a website. It is a digital platform that can be used to share information and media across the general purpose Internet (as opposed to internal sites). I have been asked by several people about website development. So I compiled this handy little FAQ type article so that you have all the answers in one place.

Basic questions

What do I need to create a website?
You need a web address, sever space for hosting your site and access to a decent Internet connection.

How can I obtain a web address?
You can obtain a web address from a domain registrar or a reseller. If you are also looking hosting options, you can also get a domain name from the same company that hosts your site. I use two companies; one for my domain and one for my hosting.

What domain name should I use?
If you are looking for free web hosting, please read the next question. But if you decided to create your own top-level domain (TLD) then I recommend using common/generic domains such as .COM, .ORG, .NET, etc. The .COM would be the preferred one.

If you are developing a website for country specific item or the name you desired is not available, you can get with a country code top-level domains. For example, cbc.ca. But beware of legal restrictions such as residency requirements. Some domains like .CAs can be registered by anyone. But others like .IN, you must need an Indian physical mailing address to register. Make sure you read the requirements when going for country specific domains before you register.

Additionally please do not register domain names of established companies and organizations. This will get you in hot water. For example, if you register ucalgary.com, you may be taken to court by the UofC.

It is possible to me to have a free website?
You can get a free web address from several different companies and organizations. For example, the WordPress (WP) offers free web addresses with hosting included at WordPress. If you need more detailed information on free WP setup click here. Of course there are other free service providers out there. Feel free to search for such providers. However, one big advantage of using WordPress based free service is that if you decided to migrate your entire site to a new server later time, it can be easily done with WP installs. Note that all free services will provide you with a sub domain names as opposed to top-level domains (TLDs). For example, yourname.wordpress.org instead of yourname.com.

Website design and building questions

How can I build a website?
There are few different ways. The most complicated, but the most primitive method is to develop using basic HTML pages.

The best option is to build a site with a Content Management Program (CMS). They allow you to use pre-configured templates with almost unlimited options for customizations. This saves a lot of time and money since most people can build a website by themselves without using a third party web developers. I highly recommend using a CMS like WordPress or Drupal. Even large organizations such as University of Calgary and CNN use Drupal and WordPress for their sites. These programs are free in almost all hosting packages.

Can I build a website on my own sever?
Yes you can. You can use simple HTML pages or you can also install CMS program for free on your server.

What do I need for my own server?
If you are asking this question and you do not already know the answer, please do not build your own server. Unless you have the time, resources, knowledge and enthusiasm to maintain your own server, please do not try this method. For that reason plus it will take a long explanation, I am not going to answer this question. Do your down research and use diligence to determine if it is worthwhile to do so. Remember, it will cost you a lot more to have your own physical server than to rent (“buy”) hosting from a company.

Can I get my own email address?
Once you have your own domain top-level name, you can create your own email address. There are two ways to do this; one is to go with Google Apps or if you went with a hosting provider, the hosting package will come with an email system included.

Note that Google Apps are no longer a free service.

Content and miscellaneous

Can I promote my site on search engines?
You do not have to do anything to add your site to Google Search. But you can speed up the process via Google Webmaster Tools. You can promote your website for a fee, but only do so if you are earning money off of the site itself. It is not worth it, if it is a personal website.

What can I publish on my website?
You can publish any media (images, videos, animations, etc) and text. The media files will take a lot of space and bandwidth on the server. Therefore be resourceful of what you publish and be smart. You can post videos on YouTube and embed the video to your website to save storage. You can reduce the size of the image by reducing high resolution images, etc.

While you can publish anything you want, beware of the local and international laws. Even in Canada, you are not allowed to publish certain items online such as other people’s personal information without explicit written permission, images obtained (copied) from other websites without appropriate reference or clearance, etc. In some counties publishing pornography or even birth control, etc may be considered illegal.

Can I sell items and/or accept donations online?
In most countries, including Canada, yes you can. But make sure you keep records of all your transactions for tax and auditing purposes. If you are a small company or if this is your personal website, I recommend using PayPal as a payment processing service provider. For donations this can be done simply via a link to the PayPal site. For ecommerce, you would have to install either a module on your CMS or install an ecommerce specific CMS to integrate payments via PayPal. Unless you are a large company or a growing small business, I recommend against accepting direct credit card payments.

Can I publish a website in languages other than English?
Yes you can. Simply write the pages in whatever the language you prefer. But for non-English languages, the site must have proper language coding at the top of the code. Even English and Chinese can be setup on the same page using UTF-8 Encoding standards.

Where can I learn HTML?
Google is your friend! Even with a CMS, you must learn at least basic HTML tags in order to maintain a website.

I am sure you probably have more questions. If you do not find this page helpful, try searching online or you can contact me with your questions.

Updating Electrical Components

Last year I published an article on home electrical wiring basics. When I looked back at that document, I realized that I have missed several aspects of electrical wiring. This article will complement the previous by expanding the subject matter.

What can you do without professional help?

In Calgary, Canada, the municipal laws allow the home owners to replace devices from the home electrical system. Additionally, the laws also allow home owners to undertake small renovations (without adding or removing new walls or electrical/plumbing fixtures) without any professional help. However, if you decided to add a new electrical outlet, then you must get proper permits from the City Government. Please do not take this as a legal advice. Contact your municipal or other regulatory body for information on allowed modifications to your electrical system.

Electric shock alert

For the purpose of replacing traditional electrical fixtures with automated (or networked) fixtures with same certification, in municipalities you do not need a permit. It is like just replacing a light switch with another light switch. But if you are unfamiliar with electrical work do not attempt to replace electrical fixtures. Contact a professional electrician for help. I, Sanuja Senanayake or the site sanuja.com will not take any responsibility for any personal injury or property damage.

Not all switches can be replaced

In North America, the home electrical circuits are composed of several types of wires. Each type plays a different role in maintaining the current flow from the main box to the electrical fixtures. These wires are not interchangeable nor can be easily replaced. The type of wires in a typical household can be summarized as:

Hot Wire = Black; carries the electrical potential from the main box to the unit
Common/Neutral Wire = White; carries the return current back to the main box
Ground Wire = Copper (no coloured casing) or Green; used for grounding the circuit for protecting from electrical shock, overloads, lightning, etc.
Returns = usually white but check with a multimeter; also called “Runner(s)” used for light fixtures or such switch circuits.

Not all traditional switches can be converted to automated or remote (“smart”) control switches. Almost all smart switches require constant power. This is achieved using the Common Wire and the Hot Wire. While almost all electrical switches and receptacles will have a Hot Wire, not all of them will have a Common Wire. Especially for light fixtures, I found that some boxes in my house had Runners instead of a Common Wire. This can be a major problem for home automation enthusiasts.

If you have switches without a Common Wire, you have two options. The easiest one is to buy plug-and-play smart switch. For example, you can buy a Z-wave electrical screw-in lamp socket ON/OFF Module (Eg. Everspring AN145). The only downside is that the light switch itself must always be at ON position in order for the smart switch to work. This is however the safest and the cheapest way to fix the Common Wire problem. There are other modules for appliances and equipment that plug into wall receptacles (Eg. Evolve LDM/LPM-15). They are very easy to use and acts like mediator between the unit and the fixture.

The alternate option is to route a Common Wire from a nearby electrical box within the same circuit. The key is the Common Wire must be from the same electrical circuit as the unit that you will be replacing. Use the proper gauge white (cover) wire for the routing. Instead of routing a single wire, I recommend using a cable (lowest possible would be two wire cable) for added durability and protection. You can clip the extra wire on both ends and may be used for future electrical needs.

Common Wire is routed between two switches.
Common Wire is routed between two switches.

You can see the patches on the dry wall. I had to create few opening to route the wire within the wall. I also drilled holes on three vertical studs to pass the wire. Therefore I only used metal clips near the second switch to hold the wire to the stud.

Typical Electrical Switch

Following is a diagram of typical electrical writing for a light switch. Electricians may have wired your house differently. Please use due diligence and trace each cable and wire to what it is connecting. I found so many “questionable” circuits.

You can search online for electrical diagrams, but as mention above, make sure your circuit is wired properly. Do not always trust the colour of the wire, but trace each wire.

Very Important Points

Please us common sense when replacing electrical fixtures. If you are replacing an outdoor receptacle, make sure you have adequate weather projection for the new unit. It is also very important to either use an outdoor rated fixture or install an outdoor cover/box. Electricity and water should never mix and inadequate protection from environment may result in electrical fires or major malfunctions in the circuit.

If you are replacing a fixture on a critical circuit, make sure your new smart fixture does not interfere with the normal operations of the circuit. For example, if you are replacing a switch on a circuit that also provides power to your home security system, make sure the switch will not adversely affect the security system’s power.

Another issue is heat. Since all network connected smart switches have antennas to broadcast and receive data, they produce heat. In fact, you can feel the heat on some switches. It is not a problem as long as you provide adequate ventilation. To do that, you should increase the depth and size of the electrical box. I have used 3 unit boxes for 2 switches just to add more room. With additional wires such as Common Wire and Ground Wire running directly to each smart switch, it also provide room for wire management.

When replacing a 60 W (watts) fixture, use a 60 W smart fixture. Do not use a fixture with lower energy rating. Using a lower wattage rated unit may result in electrical fires.

Before closing the electrical boxes with their covers, make sure all the wires are properly installed and nothing is lose. Use insulated tools such as rubber handle screw drivers. Ground yourself to avoid static discharge. Do not leave open electrical boxes or wires for long period (Eg. Overnight) even if the circuit is shut off from power.

If you are unsure of something or uncomfortable with electrical work, please contact a professional.

Choosing a thermostat

In most parts of the developed world, we live in houses that are at least ten years old (or often older). Hence homeowners spent their money on home improvements. One of the easiest ways to renovate your house is to replace the old units with new ones. Today I am going to discuss a simple item found in every Canadian household; the thermostat.

Good old days

Thermostats in the past are based on mercury switches. The temperature and humidity information is passed to the furnace, air conditioner and humidifier from a mechanical leaver inside the thermostat. Today, the same task can be done either electronically or electrically without the use of mercury or mechanical parts. Almost all modern thermostats operate by sending electrical signals via two circuits built in to the controller and the receiver on the other end.



With electronic controllers, you can buy thermostats from several different manufactures. Additionally there are many models even from the same manufacture. This is expected because modern units are not limited to manual controls. Depending on the type of the unit, you may be able to control the temperature and other aspects either remotely or via an automated system.

When purchasing a unit, here are few pointers to think about;
How old is your current furnace/heater, air conditioner and humidifier?
What are the types of input controls in your current units (can it take an electronic signal)?

If your units are old enough to replace, it may be time to replace them with a modern cutting-edge units. This way you can use any thermostat to control them. If you have an older unit, then make sure you have the right configuration for whichever the thermostat you want to install. For example, if you are missing a specific wire required for an electronic automated thermostat, you may either have to add an additional circuit box in between the controller and the heading/cooling unit or you may have to opt in for a traditional older thermostat. This is where the return policy of the store will help you out! However, you can avoid retuning an item by doing your research before you buy one.


There are several technologies in the consumer market. Most of them are proprietary technologies made by companies like Nest and Honeywell. Others have little more flexibility with built in standards like Z-wave, which can be used along with any Z-wave controller.

Most “smart” thermostats can be connected to your LAN (home network) and ultimately to the Internet. You can control these thermostats from computers and mobile devices in addition to physical controls. You can create accounts and enforce restrictions on who can control what. You can create schedules or in some thermostats can learn from your behavior and automatically create schedules for you (eg. Nest). You can create relationships between the thermostat and other units in the house. For example, you can connect a Z-wave thermostat to your front door sensor. Then you can set it up so that if the front door is opened between 4-6 PM, the temperature will increase from 19 C to 21 C. This way, when you come back from work, the house will be warmed up in few minutes. With the electronic and Internet age, the possibilities to make your house a home with technology are endless.

So when you are ready to buy a thermostat, ask yourself what do you want to do with it. Do you simply want to control the temperature? Or do you want to control the temperature via a computer in the house or mobile device or anywhere in the world? Of course, how much will you be spending?

Proprietary or Independent

Personally, I prefer flexible options because it limits dependencies. If you have a Nest thermostat, for your remote controls you will depend on the Nest network. Any issues there including technical or otherwise (like free to paid service), must go through Nest company. Contrast this with a Z-wave unit like Honeywell VisionPro Thermostat, in which the remote control is done through your home LAN and Internet connection. To me, it is no brainier; Z-wave is better for independence.

Here are some key things about proprietary verses the Z-wave based thermostats (or any other equipment). With proprietary technologies you get much better security and reliability. Since millions of others also use the same network and technology, you will provide with cutting edge support for your thermostat. It is also easier to setup a Nest thermostat than to setup a Z-wave thermostat for most people. However, you will be giving up your personal information such as “Away from home time/temperature” to a server somewhere in the world. Since you are one of millions of others on the same network, you may be vulnerable to cyber security issues. Additionally, you have no control over the network itself. While it may be reliable and secure, if the company responsible for the network decided to charge you for the remote service, you have no choice but to pay (or stop using the remote features).


Installation is very simple assuming you have all the right wires. In other words, as long as you have a compatible heating/cooling unit, you can install the thermostat by yourself. I found the programming the thermostat is harder than the actual installation process. But it is just me!

How to fix overclocking failed error

This is a well documented boot failure issue on most Asus motherboard. When the issue arise, the message, “Overclocking Failed! Please enter setup to re-configure your system.” will be displayed on start up before the system goes into boot sequence. So, how can you fix this?

A typical Overclocking Failed! error.
A typical Overclocking Failed! error.

What causes the problem?

The K-type processors from Intel can be safely overclocked. The manufacture Asus has several built-in functions on their motherboard that takes advantage of this Intel K-type processors. The motherboard has a program in BIOS to change the processor and RAM memory speed. If you have not manually overclocked the RAM or the processor before this error was displayed, then it is most likely caused by memory frequency issue.

The Intel CPU and the memory frequency is often changed during an overclocking process. It also may change during a boot-up or shutdown process. When either boot-up or shutdown processes does not go to completion due to power failure or other issues, then it may result in the frequency for CPU/RAM stuck in a higher than normal value.

Here is how you fix it

As instructed on the error screen, go to your BIOS setup (F2 or DEL at the start-up). The first option is obvious; press F5 (or find other means) to set all parameters in BIOS to Default. Now reboot and if that fails, then try the following.

1) Change the profile under “System Performance” to “Power Saving” profile.

Asus Main BIOS page (EZ Mode)
Asus Main BIOS page (EZ Mode)-Click on enlarge.

2) Go to “Advanced Mode” (select or F7-check above image) then select “Ai Tweaker” tab from the top.

Ai Tweaker tab under Advanced Mode
Ai Tweaker tab under Advanced Mode-Click on enlarge.

3) Change the system Level Up to “Auto”. Note: if “Auto” does not fix your problem, change the setting to the lowest level.

Target DRAM Speed and System Level Up selector.
Target DRAM Speed and System Level Up selector-Click on enlarge.

4) The Target DRAM Speed should read around 1600MHz (or lowest RAM speed possible).

5) Select “Boot” tab from the top and make sure the “Boot Option #1” under “Boot Options Properties” reads “Windows Boot…”.

Boot Option Properties --> Boot Option #1 = Windows Bo...
Boot Option Properties –> Boot Option #1 = Windows Bo…-Click on enlarge.

6) Now press “Exit” at the top and select “Save Changes & Reset”. Your system should boot up normally.

If this also failed to resolve the problem, you are not in danger of losing your computer. Go back to “Advanced Mode” and select “Advanced” tab from the top. Now change the Intel CPU variables until you find a solution. This is under CPU Configuration section. Try different combinations. I recommend disabling “Limit CPUID Maximum” and “Intel Visualization Technology”. That is what worked for my computer.

Advanced Intel CPU BIOS option
Advanced Intel CPU BIOS option–Click on enlarge.

Advanced Intel CPU BIOS options-CPU Configurations
Advanced Intel CPU BIOS options-CPU Configurations–Click on enlarge.

Please note that the above instructions are not Scientific nor approved by the manufactures. They are based on my personal experience. I have fixed few Asus computers with this issue by following the steps. There is no way I can guarantee that these steps will also work for your system. Use the information with caution.