Showing posts with label Interview Questions. Show all posts
Showing posts with label Interview Questions. Show all posts

Monday, 14 April 2014

PHP Interview Questions

How to prevent web browser to image caching?       

The simple way to prevent image caching is to append time stamp with the name on image.
Ex- <img src=’image.jpg?<?php echo time() ?>’ />

What is the difference between Primary Key and Unique key?    

Both Primary Key and Unique Key enforces uniqueness of the column on which they are defined. But by default Primary Key creates a Clustered Index on the column, where are Unique Key creates a Non clustered Index by default. Another major difference is that, Primary Key doesn’t allow Nulls, but Unique Key allows one NULL only.

What is the difference between $name and $$name?

$name is variable where as $$name is reference variable
like $name=Sadiq and $$name=Akhtar so $Sadiq value is Akhtar.

What’s the difference between md5(), crc32() and sha1() crypto on PHP?        

The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit md5() returns a 160 bit value. This is important when avoiding collisions.

jQuery interview questions


How is body onload() function is different from document.ready() function used in jQuery?

1. We can have more than one document.ready() function in a page where we can have only one onload function.
2. Document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.
  • Is jQuery a library for client scripting or server scripting?
    Ans: Client scripting
  • Is jQuery a W3C standard?
    Ans: No
  • What are jQuery Selectors?
    Ans: Selectors are used in jQuery to find out DOM elements. Selectors can find the elements via ID, CSS, Element name and hierarchical position of the element.
  • The jQuery html() method works for both HTML and XML documents?
    Ans: It only works for HTML.
  • Which sign does jQuery use as a shortcut for jQuery?
    Ans: $(dollar) sign.
  • What does $("div") will select?
    Ans: It will select all the div element in the page.
  • What does $("div.parent") will select?
    Ans: All the div element with parent class.
  • What is the name of jQuery method used for an asynchronous HTTP request?
    Ans: jQuery.ajax()
  • What is CDN and what are the advantage of loading jQuery framework from CDN?
  • How to load jQuery locally when CDN fails?
  • What is jQuery.noConflict()
  • Difference between $(this) and 'this' in jQuery
  • jQuery empty() vs remove()
  • jQuery remove() vs detach()
  • Is window.onload is different from document.ready()
  • How to check if element is empty
  • width() vs css('width') and height() vs css('height')
  • How to Check element exists or not in jQuery
  • Difference between bind() vs live() vs delegate() function
  • How to use jQuery Selectors with Examples
  • How to Disable-Enable all controls of page using jQuery
  • What are the possible problems can occur when jQuery and Ajax used in ASP.NET?
  • Why to use Google hosted jQuery CDN?
  • Q1. What is jQuery?
    Ans: jQuery is Lightweight and CrossBrowser JavaScript Library/Framework which helps in to traverse HTML DOM, make animations, add Ajax interaction, manipulate the page content, change the style and provide cool UI effect. The biggest advantage over Javascript is that it reduces lines of code as huge code written in JavaScript, can be done easily acheived with jQuery in few lines.

    Q2. Why jQuery?
    Ans: Due to following functionality.
           1. Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
           2. AJAX functions
           3. CSS functions
           4. DOM manipulation
           5. DOM transversal
           6. Attribute manipulation
           7. Event detection and handling
           8. JavaScript animation
           9. Hundreds of plug-ins for pre-built user interfaces, advanced animations, form validation etc.
           10. Expandable functionality using custom plug-ins

    Q3. Is jQuery replacement of Java Script?
    Ans: No. jQuery is not a replacement of JavaScript. jQuery is a different library which is written on top of JavaScript. jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML. 

    Q4. What is the basic need to start with jQuery?
    Ans: To start with jQuery, one need to make reference of it's library. The latest version of jQuery can be downloaded from jQuery.com.

    Q5. What does dollar Sign ($) means in JQuery?
    Ans: Dollar Sign is nothing but it's an alias for JQuery. Take a look at below jQuery code. 
    $(document).ready(function(){
    });
    
    Over here $ sign can be replaced with "jQuery" keyword. 
    jQuery(document).ready(function(){
    });
    Q6. Is there any difference between body onload() function document.ready() function used in jQuery?
    Ans: document.ready() function is different from body onload() function due to 2 reasons.
           1. We can have more than one document.ready() function in a page where we can have only one body onload function.
           2. document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.

    Q7. Can we have multiple document.ready() function on the same page?
    Ans: YES. We can have any number of document.ready() function on the same page.

    Q8. What are the different type of selectors in Jquery?
    Ans: There are 3 types of selectors in Jquery
           1. CSS Selector
           2. XPath Selector
           3. Custom Selector

    Q9. Name some of the methods of JQuery used to provide effects?
    Ans: Some of the common methods are :
           1. Show()
           2. Hide()
           3. Toggle()
           4. FadeIn()
           5. FadeOut()

    Q10. What is JQuery UI?
    Ans: jQuery UI is a library which is built on top of jQuery library. jQuery UI comes with cool widgets, effects and interaction mechanism. 

PHP-Mysql Interview Questions

PHP, Ajax, Javascript , HTML, Mysql

How can we submit a form without a submit button?

The main idea behind this is to use Java script submit() function in order to submit the form without explicitly clicking any submit button. You can attach the document.formname.submit() method to onclick, onchange events of different inputs and perform the form submission. you
can even built a timer function where you can automatically submit the form after xx seconds once the loading is done (can be seen in online test sites).

In how many ways we can retrieve the data in the result set of MySQL using PHP?

You can do it by 4 Ways
1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc
 
What is the difference between mysql_fetch_object and mysql_fetch_array?

mysql_fetch_object() is similar tomysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
 
What is the difference between $message and $$message?
 
It is a classic example of PHP’s variable variables. take the following example.$message = “Mizan”;$$message = “is a moderator of PHPXperts.”;$message is a simple PHP variable that we are used to. But the $$message is not a very familiar face. It creates a variable name $mizan
with the value “is a moderator of PHPXperts.” assigned. break it like this${$message} => $mizanSometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically.
 
How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’
using regular expression of PHP?

preg_match(”/^http:\/\/.+@(.+)$/”,’http://info@abc.com’,$found);
echo $found[1];
 
How can we create a database using PHP and MySQL?

We can create MySQL database with the use of
mysql_create_db(“Database Name”)
 
What are the differences between require and include, include_once and require_once?

The include() statement includes and evaluates the specified file.The documentation below also applies to require(). The two constructs are identical in every way except how they handlefailure. include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missingfile to halt processing of the page.
include() does not behave this way, the script will continue regardless.
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only differencebeing that if the code from a file has already been included, it will not be included again. As the name suggests, it will be included just once.include_once() should be used in cases where the same file might be included and evaluated more than once during a particularexecution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
 
Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?
 
Yes we can use include() more than one time in any page though it is not a very good practice.

 
What are the different tables present in MySQL, which type of table is generated when we are creating a table in the following syntax:
create table employee (eno int(2),ename varchar(10)) ?

Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM
MyISAM is the default storage engine as of MySQL 3.23 and as a result if we do not specify the table name explicitly it will be assigned to the default engine.
 
How can we encrypt the username and password using PHP?
 
The functions in this section perform encryption and decryption, and compression and uncompression:
encryption decryptionAES_ENCRYT() AES_DECRYPT()ENCODE() DECODE()
DES_ENCRYPT() DES_DECRYPT()
ENCRYPT() Not available
MD5() Not available
OLD_PASSWORD() Not available
PASSWORD() Not available
SHA() or SHA1() Not available
Not available UNCOMPRESSED_LENGTH()

Write a select query that will be displayed the duplicated site name and how many times it is duplicated ?

SELECT sitename, COUNT(*) AS NumOccurrences FROM tbl_sites GROUP BY sitename HAVING COUNT(*) > 1

 What does isNaN function do?

 Return true if the argument is not a number.