Tag: MySQL

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.

Simple RESTful API webservice demo in PHP

API URL :  http://domain_name/api.php

Input param :

API Call Request :

Successfull Output :

Error Output :

API Script (api.php) :


You can download all above demos from below link :

Download Source Code


Browse source code in github : https://github.com/sagarsdeshmukh/RESTful_Webservice_Demo

How to import excel file data into mysql database in PHP ?

To import excel file data into web application (in MySQL database) is one of simplest task.

– PHP version 5.2.0 or higher


  1. Read Excel file data in PHP using “PHPExcel” library
  2. Insert the fetch data into MySQL database

We have excel file , example_file.xlsx

First we will create table in MySQL database to store excel file data. as per the our excel file the database query to create a table structure is as follows,

Fetch excel file data and insert into database as per below –


Download Source Code

Happy Coding 🙂