Archives for: May 2017

How do MySQL indexes work?

What is MySQL indexes ?

A database index is a data structure that improves the speed of operations in a table. Indexes can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records.

How do MySQL indexes work?

Basically an index on a table works like an index in a book (that’s where the name came from):

Let’s say you have a book about databases and you want to find some information about, say, storage. Without an index (assuming no other aid, such as a table of contents) you’d have to go through the pages one by one, until you found the topic (that’s a full table scan). On the other hand, an index has a list of keywords, so you’d consult the index and see that storage is mentioned on pages 113-120,231 and 354. Then you could flip to those pages directly, without searching (that’s a search with an index, somewhat faster).

Of course, how useful the index will be, depends on many things – a few examples, using the simile above:

  • if you had a book on databases and indexed the word “database”, you’d see that it’s mentioned on pages 1-59,61-290, and 292 to 400. In such case, the index is not much help and it might be faster to go through the pages one by one (in a database, this is “poor selectivity”).
  • For a 10-page book, it makes no sense to make an index, as you may end up with a 10-page book prefixed by a 5-page index, which is just silly – just scan the 10 pages and be done with it.
  • The index also needs to be useful – there’s generally no point to index e.g. the frequency of the letter “L” per page.

Basic Linux Commands

              When dealing with the Linux operating system, commands are required as inputs to inform or direct a computer program to perform a specific operation. Understanding the most basic Linux commands will allow you to successfully navigate directories, manipulate files, change permissions, display information such as disk space, and more. Obtaining basic knowledge of the most common commands will help you easily execute tasks via the command line.


Below are the Some of basic linux commands:

ls = If you run ls without any additional parameters, the program will list the contents of the current directory in short form.

ls -l = detailed list

ls -a = displays hidden files
cp = Copies sourcefile to targetfile.
cp -r = Copies recursively (includes subdirectories)
mv = Copies sourcefile to targetfile then deletes the original sourcefile.
mv -b = Creates a backup copy of the sourcefile before moving
rm = Removes the specified files from the file system. Directories are not removed by rm unless the option -r is used.
rm -r = Deletes any existing subdirectories
rmdir = Deletes the specified directory, provided it is already empty.
cd = Changes the current directory. cd without any parameters changes to the user’s home directory.
mkdir = Creates a new directory.
cat = The cat command displays the contents of a file, printing the entire contents to the screen without interruption.
cat -n = Numbers the output on the left margin
less = This command can be used to browse the contents of the specified file. Scroll half a screen page up or down with PgUp and PgDn or a full screen page down with Space. Jump to the beginning or end of a file using Home and End. Press Q to exit the program.
grep = The grep command finds a specific searchstring in the specified file(s). If the search string is found, the command displays the line in which the searchstring was found along with the file name.
df = The df (disk free) command, when used without any options, displays information about the total disk space, the disk space currently in use, and the free space on all the mounted drives. If a directory is specified, the information is limited to the drive on which that directory is located.
df -h = shows human readable output of disk usage
du = This command, when executed without any parameters, shows the total disk space occupied by files and subdirectories in the current directory.
du -sh = Shows current folder size
du -sh * = List files/folders with their size in current folder
free = The command free displays information about RAM and swap space usage, showing the total and the used amount in both categories.
free -m = Shows output in human readable format
date = This simple program displays the current system time. If run as root, it can also be used to change the system time. Details about the program are available in date.
top = top provides a quick overview of the currently running processes. Press H to access a page that briefly explains the main options to customize the program.
kill = [You can kill processes which are executed only by you] Unfortunately, sometimes a program cannot be terminated in the normal way. However, in most cases, you should still be able to stop such a runaway program by executing the kill command, specifying the respective process ID (see top and ps).
kill sends a TERM signal that instructs the program to shut itself down. If this does not help, the following parameter can be used:
kill -9 = [You can kill processes which are executed only by you] Sends a KILL signal instead of a TERM signal, with which the process really is annihilated by the operating system. This brings the specific processes to an end in almost all cases.
ping = The ping command is the standard tool for testing the basic functionality of TCP/IP networks. It sends a small data packet to the destination host, requesting an immediate reply. If this works, ping displays a message to that effect, which indicates that the network link is basically functioning.
passwd = Users may change their own passwords at any time using this command. Furthermore, the administrator root can use the command to change the password of any user on the system.
clear = This command cleans up the visible area of the console. It has no options.


Useful options
mv -f force move by overwriting destination file without prompt
mv -i interactive prompt before overwrite
mv -u update – move when source is newer than destination
mv -v verbose – print source and destination files
man mv/info mv help manual


List the commands to display the contain of files

head, tail, cat less, more etc

eg.  $ cat file_name.txt

For more details check below links –

Hope the above article is helpful for you !

Stripe API implementation error/exception handling

Stripe error handling

Stripe error handling

Stripe API libraries raise exceptions for many reasons, such as a failed charge, invalid parameters, authentication errors, and network unavailability. The Stripe recommends for writing code that gracefully handles all possible API exceptions.

Below Error Handling code is compatible with latest stripe API version


For old stripe versions i.e Stripe API v1.18.0 use below Error Handling code

For more details please check .


What is different between abstract class and interface in PHP?

1) – For abstract class a method must be declared as abstract. Abstract methods doesn’t have any implementation.
– For interface all the methods by default are abstract methods only. So one cannot declare variables or concrete methods in interfaces.

2) – The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same (or a less restricted) visibility.
– All methods declared in an interface must be public.

3) – Abstract class can contain variables and concrete methods.
– Interfaces cannot contain variables and concrete methods except constants.

4) – A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.
– A class can implement many interfaces and Multiple interface inheritance is possible.

5) – Abstract class can contains constructor
– Interfaces cannot contain constructor

6) – Only complete member of abstact class can be static
– Member of interface can not be static