Category Archives: Computer Science

Mostly programming and coding work related to PHP, HTML, Java, C#, Python and any other that I come across. May also include consumer level articles.

Database Management System for Online Ticket Sales

Database Management System (DBMS) of online ticket sale for the stage play “Kusa-Paba” at the University of Calgary Theater.

Abstract and Project Description

The University of Calgary Theater has 500 available seats. This particular DBMS is built to allow users to order and purchase tickets online. Tickets sold by agents can also be entered to the system using the agents’ interface. Only a designated set of seats are available for sale. Some are as for reserved guests and others are designated as House Seats hence they are not available for sale. The designated seats for sale are categorized for different price levels; $50.00, $30.00 and $20.00 (Figure 1). The price levels are further broken down for adults and children.

Continue reading Database Management System for Online Ticket Sales

Maximum Input Variables WP Error

The max_input_vars limitation error is a very common issue that most WordPress web developers and website owners may encounter at some point in their career. Few days ago, my website also experienced the same problem. The solution is very simple; increase the value assigned to max_input_vars in the PHP configuration file on the web server. However, depending on server setup, you may have to do few more things to get this problem fixed.

Warning
Editing php.ini may result in complete failure of the php module and it may put your website out of service. If you are hesitant about something, hire a professional. I take no responsibility for any issues arise out of the following instructions.

Continue reading Maximum Input Variables WP Error

Recover Data from Internal Hard Drives

Computers are made of multiple different components. Not all components are vital to operations of a computer. For example, failure of a disk drive (DVD/BlueRay) would most likely have little to no impact on other functions of a computer. But failure of a vital component such as the processor, power supply or malfunctioning of a hard drive will lead to a situation where the computer is no longer operational. Do not panic. You may be able to recover data from such computers using either an external enclosure or using an IDE/SATA to USB adapter.

You can recover data from most “broken” computers even if you are not tech savvy. If you perform the recovery at home (or business) by yourself, you will save from $100 to $2000 CAD (2016 estimates) on data recovery costs.

External Enclosures

External enclosures are bit more expensive than the IDE/SATA to USB adapters. There are few advantages of this method for example, encloses these allow you to use the hard drive as an external storage device, if the hard drive is still in good condition. Another advantage of this method is that most enclosures are compatible with multiple interfaces such as USB 2.0, USB 3.0, older FireWire, etc. Higher end external enclosures will also have the ability to connect to a network as a Network Attached Storage (NAS) or to connect to multiple computers simultaneously.

Installation of external enclosures is fairly simple. To setup, attached the IDE or SATA connector and power supply cable from the enclosures’ printed circuit board (PCB) to the internal hard drive. You may also follow the instructions posted under IDE and SATA to USB Adapters. They are very similar to each other.

Example of a External Enclosure with connection points highlighted.
Example of a External Enclosure with connection points highlighted.

Image modified from: https://en.wikipedia.org/wiki/Disk_enclosure#/ media/File:Usb_firewire_hard_disk_enclosure.jpg

IDE and SATA to USB Adapters

The IDE/SATA to USB adapters operate on the same fundamental principles as external enclosures. The major difference is that they do not have enclosure casing hence mostly used by computer technicians. The best advantage of using this method is that you can access the hard drives of computers and servers without completely removing the device from the main unit. The adaptors have a simple control board with IDE, SATA or other connectors and a power supply. As long as you can access these connectors on the hard drive, you can recover data from a unit without wasting time on removing components. These adaptors also take less space hence they can be easily transported and stored. Another advantage is the price. I must admit it is not a very good advantage because the price differences between IDE/SATA to USB adapters and external enclosures have significantly decreased in recent years.

Installation of these adaptors is bit more complicated than the external enclosures. Here are some suggestions for installation and usage of IDE/SATA to USB adapters.

Step 1: Ground yourself by using a wrist strap or by connecting a wire between yourself and the computer case (metal).

Step 2: Locate your internal hard drive and get clear access to data connector (IDE/SATA) and power connector of the unit.

Internal hard drive with attached cables from motherboard and PSU.
Internal hard drive with attached cables from motherboard and PSU. Click for enlarge image.

Step 3: Remove the attached IDE/SATA cable that runs between the motherboard and the hard drive. Remove the power rail connection between the computer’s Power Supply Unit (PSU) and the hard drive.

SATA and power connectors on a typical internal hard drive.
SATA and power connectors on a typical internal hard drive. Click for enlarge image.

Step 4: Attach the SATA connector from the IDE/SATA-USB to the hard drive and power connector from the IDE/SATA-USB power unit.

SATA and power connections from the IDE/SATA to USB adapter.
SATA and power connections from the IDE/SATA to USB adapter. Click for enlarge image.

Step 5: First power on the internal hard drive by plugging the IDE/SATA-USB power unit to a wall outlet. Then connect the control board to the IDE/SATA cable and the USB cable. Connect the USB cable to the computer.

USB connection to the computer via the IDE/SATA to USB adapter.
USB connection to the computer via the IDE/SATA to USB adapter. Click for enlarge image.

You should now have a USB attached mass storage unit on your computer just like a USB key. However, if this is not shown on the first attempt, disconnect power to the IDE/SATA to USB adapter, wait few seconds and reconnect the power.

Limitations

If the internal hard drive data is protected through hardware or software encryption, then this simple recovery method may not work. Sometimes only the main user folder such as “Documents” or “My Documents” is encrypted by the operating system (OS). In this case you will be able to extract data from all other locations except the user folder. For instance, Windows XP, 7 and 8 usually encrypt user folder by default except if the user change the default settings. This limitation also applies to professional data recovery services. If the password or encryption key is known, then data recovery companies may charge you a premium and may be able to recover your data. If the password or encryption key is unknown, then depending on how strong the encryption is no one can guarantee recovery success.

Another limitation is the differences in interfaces and communication protocols. Older products may have operating and file systems that are incompatible with modern computers. Hence, you will not be able to read information from the extracted drive. The best solution for this is to find an older unit that can read such data files and use that in the recovery process.

Corrupted files can also pose a major problem for recovering data. Sometimes when hard drives fail, they can overwrite meaningful data with useless junk. This can be reserved but at a very high cost because this type of recovery require military grade data recovery tools.

Finally, if the components of the hard drive have failed, then you have to send the drive to a laboratory that can take apart the disks and read it in a special dust free, static free and highly controlled environment. This is probably the most expensive recovery option and most likely be used by large corporations and government agencies than consumers and small businesses.

Installing a router and routing basics

Modem, Router and Modem-Router combination

The term routing has been in used long before the Internet age. In the past, routing refers to distribution of mail or landline (traditional) phone calls through mail sorting centers or telephone switching centers. Today, a router is an electronic networking device that acts as the “middle guy” between two or more data lines from different devices. A router manages the packets (data) migration between computers within the local area network (LAN) and provides distributed Internet (Wide Area Network) access to the local clients.

There are differences between a router and a switch. A router assigns individual identification tags for each unit in the LAN known as internal IPs through a method called Dynamic Host Configuration Protocol (DHCP). DHCP help each individual unit to communicate properly with the rest of the units in the LAN and on the Internet (WAN). A network switch connects data lines from one single network for another without routing. A switch is often used in conjunction with a router to add additional physical ports or wireless connections to a network. A switch must obtain DHCP IP addresses from a router within the same network to work because switches do not have the DHCP engine.

Modem is a unit that converts signals from the WAN and transcribes into LAN format for internal use. It is the main communication hub between your home and the Internet Service Provider (ISP). It is usually provided by the ISP and sometimes contains a built-in router. If your modem has more than one LAN connection, then it must have an internal router. Without a router and its’ DHCP capabilities, you would not be able to connect more than one unit to the modem.

If you want to use a separate router with these modem-router combination units, you have to remove the routing capabilities of the unit. You can do this either by contacting your ISP or by following instructions on your specific model. A router is connected to the (or a) LAN port of your modem.

You may ask what is DHCP? DHCP is like a local address assignment office. When you paid for your Internet connection, usually the cable or telephone company assigns you an IP address known as the external IP. Each computer/network unit requires a unique IP address to communicate with other network equipment. But almost every household and business has more than one computer/network unit. The DHCP creates local addresses to separate each computer/network unit while maintaining the connection to outside world using just single IP address; the external IP. Another way to look at this is the router’s DHCP is like an intercom internal telephone exchange; one main phone number with multiple extensions. Each computer/network unit has their own internal IP (just like a telephone extension), but all units can be reach though a single Internet connection to the outside world. You cannot use a one Internet connection with a single IP to connect several units without a DHCP system.

Parts of a Router

Most consumers are not interested in internal hardware of networking equipment. However, it is important to have a familiarity with at least the external parts of a router in order to make an informed purchasing decision. The following diagram shows the basic parts; the WAN (Internet) port, LAN (local) ports, reset switch and the WPS push button. Depending on the type of router, the location of these may differ. Generally the WAN port is coloured or marked differently from the LAN ports. The reset button is usually a pinhole button where you need a pin/pen tip to press it.
parts_dir-890r
parts_wrt1900ac

Above: Two images of a D-Link router and a Linksys router. 1. WPS button and it is usually pops out of the back surface. 2. LAN ports. Typically there are four ports on consumer grade routers. 3. WAN (Internet) port where the ISP connection is attached. 4. Rest button and unlike the WPS it is usually a pinhole button. This prevents accidental hard resets. Click on images to enlarge versions.

WAN port: The connection from your modem provided by your ISP will connect to this port via a CAT5e or CAT6 network cable (regular computer network cable).

LAN ports: Any computer or device can be connected to one of these ports. Usually only about four to five LAN parts are provided by the router manufactures. You may increase the number of LAN ports by attaching a network switch. A network switch can be used to increase the number of LAN ports from 4 to 50+. For a general home use with a family of four, I would recommend a simple 4 or 6 port switch or router.

WPS button: This is a standard secure WIFI connection method. If a device is equipped with the WPS (Wifi Protected Setup) button or software and a compatible wireless card, it can be connected to the wireless LAN by pressing the buttons on both units. Please follow the instructions on your specific router and the device for configuration.

Rest button: There are several things that can be obtained from the reset button. As the name implies, it can be used to reset the router to factory settings. Additionally, some router will allow the users to even rest set the router firmware all the way back to the original version. Depending on the router if you hold down the reset button for a short period, generally it will result in a factory default. If you hold the button for more than five seconds of so, it may reset the whole unit back to the original factory setting.

Installing a Router

Consumer routers currently in the market are usually plug-and-play type units. Manufactures includes quick install guides for faster setup. Depending on the manufacture and the quality of the product, a router can be as simple as just a DHCP server with few basic features all the way up highly customizable unit with as complex as VPN configurations (higher price units have more features). For home use I recommend a simple basic router. But if your house is large (eg. over 1500 sqft) or the wireless connection is not reaching every corner of the house, you should invest in a high-end router.

Typically a router can be installed by:

    1) Plug-in the Internet cable and at last one wired LAN computer.
    2) Turn on the power to the router and wait for few seconds (refer to specific manufacture instructions).
    3) Open a web browser on your LAN connected computer and either type in the router’s internal IP address or in “smart routers” the web address provided by the manufacture.
    4) Follow the “quick setup” or “automatic setup” or “plug-n-play setup” (each manufactures will have a different term to describe easy setup feature) to configure the router.
    You will have Internet with DHCP at the end of the Step 4. If that fails, do not immediately reboot the router. Instead wait few minutes (~10 min) because sometimes it takes more time than what manufacture stated to complete the initial setup. If there is still no connection, then reboot the router by physically disconnecting-reconnecting the power supply to the router.

Configuring a Router or Routing system of a modem

Computers

Simply plug-in the computer to a LAN port using a CAT5e or CAT6 cable. For wireless, use either the provided password by the manufacture or the new password you have created. Make sure to pick the wireless network name or SSID you have created during the setup of the router to find your network.

IP/Network Cameras

IP or network cameras are becoming popular due to lower prices. They are used as a deterrent against crime, baby monitors, pet monitors or simply for fun. While the “smart” IP cameras will allow you to view the live feed from anywhere in the world using a mobile application, you can also get direct access to most of the IP cameras from your web browser. To do this, you should reserve the internal IP of the camera using DHCP reservation in your router. Otherwise, every time the router reboots (power failures, etc) a new internal IP will be issued to the device. By reserving the internal IP, you can use the same internal IP to access the camera from any web browser by entering the internal IP address.

The DHCP reservation feature can be found in several places in the firmware (router software) depending on the routers’ model number and the manufacture. Please refer to the user manual or call the 1-800 helpline if you are uncomfortable with changing router configurations manually.

An example of a typical DHCP Reservations Table with three devices with reserved internal IPs.
An example of a typical DHCP Reservations Table with three devices with reserved internal IPs.

Network Attached Servers (NAS)

Similar to IP cameras, I highly recommend DHCP reservation for NAS servers. However, just like the IP cameras, most NAS server manufactures will allow you to access the home server using a mobile application or a web program regardless of the internal IP address. Additionally, if the NAS server is properly setup with a device name, regardless of the internal IP address, you can connect to the NAS server using the device network name. The IP cameras can also be setup with network names hence eliminating the need for the DHCP reservation. But in the long run, I highly recommend both network names and DHCP reservations for NAS servers and IP cameras. It makes it easier to troubleshoot problems in the future.

Network Printers

I do not recommend manual installation of network printers. Use the software provided by the manufacture to install the printer through a LAN connection. Most companies like Brother, Cannon and HP have excellent software tools to help you install (map) the printer to your home computers. You do not need a DHCP reservation for this type of installation because the printer software will look for the printer name/ID and the MAC (Media Access Control) address for connection.

Frequently asked Questions

How often should a router be replaced? A typical consumer grade router should last for at least one year with heavy usage (large downloads and uploads with heavy bandwidth usage). Some routers can last for five to six years. But the technology is changing at a rapid rate; hence to keep up with the technology and the increasing speed of the Internet, I would recommend changing the router biennially.

Do I need a router? Please consider investing in a router:

    -If you have more than one computer or network device (such as network printers, etc) and you only have one single LAN port available on your modem
    -If your modem comes with a routing capabilities but with limited number of LAN ports
    -If you need wireless (WIFI) connections, which is not provided through a ISP modem-router combination
    -If the range of the wireless (WIFI) provided by the ISP modem-router is small or the signal strength is weak
    -If you are planning an advanced LAN network (such as hosting file servers, multiple IP cameras, etc)

I recommend buying 10/100/1000 Mbps or gigabit routers and networking devices for both consumers and businesses. I do not know why companies still manufacture 10/100 Mbps units. Routers and switches are cheap and gigabit units will benefit you especially with the higher internal file transfer rates.

How much should I spend? If you are living in a small apartment or a condo, there is no point of buying a high-end top of the range router. The prices increase with the wireless range, the strength of the signal and the processor/hardware capabilities of the unit.

When should I add a network switch? If your wired network expand to the point where you no longer have enough wired LAN ports on the router, then buy a 10/100/1000 Mbps switch. Because most families now have NAS servers for family pictures, movies, music and other media, invest in gigabit routers and switches, which will improve the internal data transfer rates. Any network equipment that handles up to 1000 Mbps will not provide the full capacity throughput to the Internet due to Internet (ISP) speed limitations. (I don’t know any Canadian company that offer 1000 Mbps Internet speeds at this time).

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.

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

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.