Thursday, February 9, 2017

PHP Interview Questions

In this page i am sharing frequently asked PHP interview Questions for Freshers and experienced candidates. These questions are frequently asked when you attend technical round in the companies.

1) What is PHP?

Ans: PHP is a server-side scripting language that is widely used for web development. By using we can write dynamic web pages efficiently and quickly. PHP is exectued on the server. It is open source scripting language,so it is free to download and use.It is very easy for learning.

2) Which Programming lanugage does PHP resemble to?

Ans: PHP programming language syntax is borrowed from perl,c. Thus PHP programming language looks same perl and C language. 

3) How do you execute a PHP script from the command line?

Ans: Just use the PHP command line interface(CLI) and specify the file name of the script to be executed as follows:
PHP

1
php script.php


4) what is meant by PEAR in PHP?

Ans: PEAR is short for "PHP extension and Application Repository". The main purpose of PEAR is to provides all kinds of php code snippets and libraries. Since PEAR is framework and repository for reusable PHP components. It also offers Command Line Interface(CLI) that can be used to automatically install "packages". A website,mailing lists and download mirrors to support the PHP/Pear community.

5) Is PHP a case sensitive programming Language?

Ans: PHP is a partially case sensitive programming language. We can use function names,class names in case sensitive manner.

6)Difference Between Echo and print statement in PHP?

Ans: Echo() and print() both are used to output strings. The speed of both statements is almost same. But the main difference is Echo() can take multiple expressions whereas print can not take multiple expression. Print() return true or false based on success or failure whereas Echo() does not return true or false.

7) How to include a file to a php page?

Ans: we can include a file using "include() or "require()" function with file path as its parameter.

8) What is difference between include() and require()?

Ans: If the file is not found by the require(),it will cause a fatal error and halt the execution of the script. If the file is not found by include() a warning will be issued but execution will continue.

9)What are the different types of errors in PHP?

Ans: There are three types of errors in PHP. They are Notices,Warnings and fatal errors.

10) How can we display the output directly to the browser?

Ans: To display the output directly to the browser,we have to use the special tags<?=and?>

11) What is the main difference between PHP 4 and PHP 5?

Ans: PHP 5 presents many additional Object Oriented Programming Features.

12) What are difference between GET and POST methods?

Ans: We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method.

13) How can we submit form without a submit button?

Ans: we can use a simple java script code linked to an event trigger of any form filed. In the java script code,we can call the document.form.submit() function to submit the form.

14) How can we encrypt the username and password using PHP?

Ans: You can encrypt a password with the following:
Mysql>SET PASSWORD=PASSWORD(\"Password\");

we can encode data using
base64_encode($string) and 

we can decode data using 
base64_decode($string);

15) How can we register the variables into a session?

Ans: we can use the session_register($ur_session_var)function


16) Is multiple inheritance supported in PHP?

Ans:  PHP includes only single inheritance, it means that a class can be extended from only one single class using the keyword ? extended ?


17) How can PHP and HTML interact?

Ans: It is possible to generate HTML through PHP scripts,and it is possible to pass information from HTML to PHP.

18) What is session?

Ans: A PHP session is no different from a normal session. It can be used to store information on the server for future use.

19) How to declare an array in PHP?

Ans: var $arr=array('apple','banana','grape');

20) What is use of in_array() function in PHP?

Ans: in_array() is used to checks if a value exists in an array.

21) What is Cookies in PHP?

Ans: Cookies are used to track user information.

22) How to set cookies in php?

Ans: cookies are used to track the information.
Syntax: Setcookie(name,value,expire,path,domain);

Example: Setcookie(\"demo\",\"mahesh\",\time()+4000);

23) How we can connect to a MySql database from a PHP script?

Ans: To connect to MySql database from PHP script,we must use mysql_connect() function as follows:

PHP

1
<!--?php $database=mysql_connect("HOST","USER_NAME","PASSWORD");
mysql_select_db("DATABASE_NAME",$databse)?--


24) How can we access the data sent through the URL with the GET method?

Ans:  In order to access the data sent via the GET method,we use $_GET array like this:

www.url.com?var=value
$vairable=$_GET[?var?];this will now contain ?value?

25) What is the meaning of a persistent Cookies?

Ans: A persistent cookie is permanently stored in a cookie file on the browser's computer. By default,cookies are temporary and are erased if we close the browser.

26) How to initiate a session in PHP?

Ans: To activate a session we have to use a function as follows:
session_start();

27) What is the difference between session_unregister() and session_unset()?

Ans: The session_unregister() function unregister a global variable from the current session and the session_unset() function free all session variables.

28) How can we change the maximum size of the files to be uploaded?

Ans: we can change the maximum size of files to be uploaded by changing upload_max_filesize in php.ini.

29) Is it possible to submit a form with a dedicated button?

Ans:  It is possible to use the document.form.submit() function to submit the form.

For Example: <input type=button value=?SUBMIT?onClick=?document.form.submit()?>

30) How do you create sub domains using PHP?

Ans: To create domains using php Wild card domains can be used. Sub domains can be created by first creating.

31) When session ends?

Ans: Session automatically ends when the PHP script finishes executing,but can be manually ended using the session_write_close()

32) What is SSL?

Ans: SSL stands for Secure Sockets Layer. This is cryptographic protocols which provide secure communications on the internet.

33) What is difference between mysql_connect and mysql_pconnect?

Ans: Mysql_connect opens up a database connection every time a page is loaded whereas mysql_pconnect opens up a connection and keeps it open across multiple requests.

mysql_pconnect uses less resources,because it does not need to establish a database connection every time a page is loaded.

34) How do you make one way encryption for your passwords in PHP?

Ans:  By using md5 function or sha1 function

35) How can we repair Mysql table?

Ans: The syntax for repairing table is:

REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED

This command will repair the table specified. If QUICK is given,Mysql will do a repair of only the index tree. If EXTENDED is given,it will create index row by row.

No comments:

Post a Comment