php interview

What are various DDL commands in SQL? Give brief description of their purposes. 
Following are various DDL or Data Definition Language commands in SQL −
 CREATE it creates a new table, a view of a table, or other object in database. 
ALTER it modifies an existing database object, such as a table. 
DROP it deletes an entire table, a view of a table or other object in the database. 
What are various DML commands in SQL? Give brief description of their purposes.
Following are various DML or Data Manipulation Language commands in SQL −
SELECT it retrieves certain records from one or more tables. 
INSERT it creates a record. UPDATE − it modifies records. 
DELETE it deletes records. 
What are various DCL commands in SQL? Give brief description of their purposes.
 Following are various DCL or Data Control Language commands in SQL −
GRANT it gives a privilege to user. 
REVOKE it takes back privileges granted from user.

2.Can you sort a column using a column alias?
 Yes. A column alias could be used in the ORDER BY clause. 

3. Is a NULL value same as zero or a blank space? If not then what is the difference?
 A NULL value is not same as zero or a blank space. A NULL value is a value which is ‘unavailable, unassigned, unknown or not applicable’. Whereas, zero is a number and blank space is a character

4. If a table contains duplicate rows, does a query result display the duplicate values by default? How can you eliminate duplicate rows from a query result? 
A query result displays all rows including the duplicate rows. To eliminate duplicate rows in the result, the DISTINCT keyword is used in the SELECT clause. 

5.What is the purpose of the condition operators BETWEEN and IN? 
The BETWEEN operator displays rows based on a range of values. The IN condition operator checks for values contained in a specific set of values.

How do you search for a value in a database table when you don’t have the exact value to search for? 
In such cases, the LIKE condition operator is used to select rows that match a character pattern. This is also called ‘wildcard’ search.

What is the default ordering of data using the ORDER BY clause? How could it be changed? 
The default sorting order is ascending. It can be changed using the DESC keyword, after the column name in the ORDER BY clause.

What are the case manipulation functions of SQL?
 LOWER, UPPER, INITCAP 

Which function returns the remainder in a division operation? 
The MOD function returns the remainder in a division operation. 

What is the use of the NULLIF function? 
The NULLIF function compares two expressions. If they are equal, the function returns null. If they are not equal, the first expression is returned.

You want to display a result query from joining two tables with 20 and 10 rows respectively. Erroneously you forget to write the WHERE clause. What would be the result? 
The result would be the Cartesian product of two tables with 20 x 10 = 200 rows. 

What is the difference between cross joins and natural joins?
 The cross join produces the cross product or Cartesian product of two tables. 
The natural join is based on all the columns having same name and data types in both the tables.

What is the purpose of the group functions in SQL? Give some examples of group functions. Group functions in SQL work on sets of rows and returns one result per group. Examples of group functions are AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE. 

The DISTINCT keyword allows a function consider only non-duplicate values. 

Say True or False. Give explanation if False.
 All group functions ignore null values. 
True. 

What’s wrong in the following query?
SELECT subject_code, count(name)  FROM students;
It doesn’t have a GROUP BY clause.
The subject_code should be in the GROUP BY clause.

SELECT subject_code, count(name)   FROM students   GROUP BY subject_code; 


What’s wrong in the following query?  
 SELECT subject_code, AVG (marks)   FROM students   WHERE AVG(marks) > 75  GROUP BY subject_code;
The WHERE clause cannot be used to restrict groups. 
The HAVING clause should be used.

   SELECT subject_code, AVG (marks)   FROM students   HAVING AVG(marks) > 75   GROUP BY subject_code;

What do you understand by a subquery? When is it used? 
A subquery is a SELECT statement embedded in a clause of another SELECT statement. It is used when the inner query, o4r the subquery returns a value that is used by the outer query. It is very useful in selecting some rows in a table with a condition that depends on some data which is contained in the same table. 

What’s wrong in the following query? 
 SELECT student_code, name   FROM students   WHERE marks =                (SELECT MAX(marks)                  FROM students                  GROUP BY subject_code);

Here a single row operator = is used with a multiple row subquery.

What are the various multiple row comparison operators in SQL?
 IN, ANY, ALL.

What is the pupose of DML statements in SQL?
The DML statements are used to add new rows to a table, update or modify data in existing rows, or remove existing rows from a table.

Which statement is used to add a new row in a database table?
The INSERT INTO statement


How do you insert null values in a column while inserting data?
 Null values can be inserted into a table by one of the following ways −
 Implicitly by omitting the column from the column list.
Explicitly by specifying the NULL keyword in the VALUES clause

How do you copy rows from one table to another? 
The INSERT statement can be used to add rows to a table by copying from another table. In this case, a subquery is used in the place of the VALUES clause.

What happens if you omit the WHERE clause in the UPDATE statement? All the rows in the table are modified.


Can you modify the rows in a table based on values from another table? Explain. Yes. Use of subqueries in UPDATE statements allow you to update rows in a table based on values from another table.

The DELETE statement is used to delete a table from the database. 
False. The DELETE statement is used for removing existing rows from a table. 

What happens if you omit the WHERE clause in a delete statement? 
All the rows in the table are deleted. 


What is the purpose of the MERGE statement in SQL? The MERGE statement allows conditional update or insertion of data into a database table. It performs an UPDATE if the rows exists, or an INSERT if the row does not exist. 


What is the difference between VARCHAR2 AND CHAR datatypes?
VARCHAR2 represents variable length character data, whereas CHAR represents fixed length character data. 

A DROP TABLE statement can be rolled back. 
False. A DROP TABLE statement cannot be rolled back. 

Which SQL statement is used to add, modify or drop columns in a database table? 
The ALTER TABLE statement. 

What is the difference between $name and $$name?  
Answers : 2 $name is variable where as $$name is reference variable  like $name=sonia and $$name=singh so $sonia value is singh. 

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

We 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? 
Answers : 5
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 use of header() function in php ?
  Answers : 12 The header() function sends a raw HTTP header to a client.We can use herder()  function for redirection of pages. It is important to notice that header() must be called before any actual output is seen..
 
Shopping cart online validation i.e. how can we configure Paypal, etc.? 
Answers : 15
Nothing more we have to do only redirect to the payPal url after submit all information needed by paypal like amount,adresss etc.

What is htaccess? Why do we use this and Where? 
.htaccess files are configuration files of Apache Server which provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all  subdirectories thereof.

How we get IP address of client, previous reference page etc ? 
Answers : 18
By using $_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_REFERER'] etc.   
 
 Question s : 19 What are the reasons for selecting lamp (Linux, apache, MySQL, PHP) instead of combination of other software programs, servers and operating systems? 
 Answers : 19 All of those are open source resource. Security of Linux is very very more than windows. Apache is a better server that IIS both in functionality and security. MySQL is world most popular open source database. PHP is more faster that asp or any other scripting language.
   
 Question s : 20 How can we encrypt and decrypt a data present in a MySQL table using MySQL?   Answers : 20 AES_ENCRYPT () and AES_DECRYPT ()
   
 Question s : 21 How can we encrypt the username and password using PHP?   Answers : 21 The functions in this section perform encryption and decryption, and compression and uncompression:  encryption decryption
AES_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()


What are the differences between procedure-oriented languages and object-oriented languages? 
Answers : 23
There are lot of difference between procedure language and object oriented like below 1>Procedure language easy for new developer but complex to understand whole software as compare to object oriented model 2>In Procedure language it is difficult to use design pattern mvc , Singleton pattern etc but in OOP you we able to develop design pattern 3>IN OOP language we able to ree use code like Inheritance ,polymorphism etc but this type of thing not available in procedure language on that our Fonda use COPY and PASTE .


What are the differences between public, private, protected, static, transient, final and volatile? 
Answer : 25
Public: Public declared items can be accessed everywhere. Protected: Protected limits access to inherited and parent classes (and to the class that defines the item). Private: Private limits visibility only to the class that defines the item. Static: A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope. Final: Final keyword prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended. transient: A transient variable is a variable that may not be serialized.  volatile: a variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile will not be optimized by the compiler because their value can change at any time.


Question s : 28
What are the differences between PHP 3 and PHP 4 and PHP 5?   
Answer : 28
There are lot of difference among these three version of php
 1>Php3 is oldest version after that php4 came and current version is php5 (php5.3) where php6 have to come 
2>Difference mean oldest version have less functionality as compare to new one like php5 have all OOPs concept now where as php3 was pure procedural language constructive like C
 In PHP5 
1. Implementation of exceptions and exception handling
 2. Type hinting which allows you to force the type of a specific argument 
3. Overloading of methods through the __call function
 4. Full constructors and destructors etc through a __constuctor and __destructor function
 5. __autoload function for dynamically including certain include files depending on the class you are trying to create.
 6 Finality : can now use the final keyword to indicate that a method cannot be overridden by a child. You can also declare an entire class as final which prevents it from having any children at all. 
7 Interfaces & Abstract Classes
8 Passed by Reference :  
9 An __clone method if you really want to duplicate an object
 10 Numbers of Functions Deprecated in php 5.x like ereg,ereg_replace,magic_quotes_runtime, session_register,register_globals, split(), call_user_method() etc



What is the functionality of the function htmlentities?   Answer : 30 Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

What is meant by urlencode and urldocode?   Answer : 33 URLencode returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in  application/x-www-form-urlencoded media type.  
urldecode decodes any %## encoding in the given string. 

How can we get the properties (size, type, width, height) of an image using PHP image functions?   
Answer : 36 
To know the Image type use exif_imagetype () function To know the Image size use getimagesize () function To know the image width use imagesx () function To know the image height use imagesy() function t 
     
 Question s : 37 How can we get the browser properties using PHP?  
 Answer : 37 By using  $_SERVER['HTTP_USER_AGENT'] variable.    
   
 Question s : 38 What is the maximum size of a file that can be uploaded using PHP and how can we change this?   
Answer : 38 By default the maximum size is 2MB. and we can change the following setup at php.iniupload_max_filesize = 2M 


List out the predefined classes in PHP? 
  Answer : 53 Directory stdClass __PHP_Incomplete_Class exception php_user_filter 


What is the maximum length of a table name, database name, and fieldname in MySQL?   
Answer : 59 
The following table describes the maximum length for each type of identifier.  
Identifier 
Maximum Length (bytes) 
Database   64 
Table         64 
Column     64 
Index         64 
Alias         255 
There are some restrictions on the characters that may appear in identifiers: 
     
 How many values can the SET function of MySQL take? 
  Answer : 60 MySQL set can take zero or more values but at the maximum it can take 64 values

Unique key?  Answer : 72 Primary Key: A column in a table whose values uniquely identify the rows in the table. A primary key value cannot be NULL.  
Unique Key: Unique Keys are used to uniquely identify each row in the table. There can be one and only one row for each unique key value. So NULL can be a unique key.There can be only one primary key for a table but there can be more than one unique for a table. 



what are magic methods?   Answers : 90 Magic methods are the members functions that is available to all the instance of class Magic methods always starts with "__". Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone() 



































































Comments

Popular posts from this blog

ARRAY