Thursday, January 26, 2012

Difference between MyISAM and InnoDB MySQL

InnoDB and MyISAM most popular storage engines in MySQL & also mostly used storage engine is the MyISAM. But most of them don't know the importance of InnoDB.

Below are the basic differences of MyISAM and InnoDB.
  1. InnoDB supports transactions which is not supported by tables which use MyISAM storage engine. Transaction is nothing but a set of MySQL queries run in an Stored Procedure as shown (BEGIN TRANSACTION ......SET of QUERIES ......END). 
  2. InnoDB has row-level locking, relational integrity i.e. supports foreign key relationship between tables, which is not possible in MyISAM.
  3. InnoDB ‘s performance for higher volume data which cannot be beaten by any other storage engines available.
Tables created in MyISAM are known to be much faster compared to tables in InnoDB. But since InnoDB supports volume, transactions, integrity it’s always a better option when we are dealing with a larger database.

Find the nth highest Salary in a table using MySQL

To find the nth highest salary or highest score in a table, below is the query to find out.

SELECT * FROM employee a WHERE n = (SELECT COUNT(*) FROM employee b WHERE a.salary <= b.salary) ;

'n'  --> By replacing n with the required value we can get the second, third, fourth highest and so on..


Tuesday, January 24, 2012

jQuery Form Validation

Tired of validating the form using javascript. Here is the code to validate the form using jQuery.


  function submit_form()
{
var formElements = $('#form_name .required'); // Reading all elements in the form which are having class as required

var error = 0;

formElements.each(function() { // Looping all the elements which are having the class name as required...
if($(this).val() == "") {  // Checking the value of the field
                                                // Showing the border color as red if the field is empty
$(this).css('border','1px solid red');
error++;
} else {
                                                // removing the border if the field has the value....
$(this).css('border','none');
}
});
}

Use the submit_form function in onsubmit of the form.

The fields in the form which need to be validated should be given as below.

<input type="text" name="field_name" class="required" />

If we add the class required for the textbox, it validates otherwise it doesnot validate the textbox.


Replace the contents in MySQL data

Below is the Query to replace the data with the required data in the column fields for the Table.

UPDATE `table_name` SET `column_name` = REPLACE(`column_name`,'search string','replace string');

table_name --> The table data which you want to change

column_name --> Particular column of the table


Thursday, January 12, 2012

How PHP Script runs


PHP is a web scripting language which is platform independent.

Below picture shows you how the php script executes when you enter the URL of the page.