Showing posts with label technical questions. Show all posts
Showing posts with label technical questions. Show all posts

Friday, 9 November 2012

PHP Interview Questions Part I

Introduction

Here we have a range of common PHP related questions and answers. If you want to know how to do something in PHP but aren't sure how, then just view the questions here and if you can't find the answer, Ask A Question.

FAQ

What is PHP?

PHP is a server side scripting language commonly used for web applications

How to include a file to a php page?

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

What’s the difference between include and require?

If the file is not found by 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.

require_once(), require(), include().What is difference between them?

require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).
So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.

How do you define a constant?

Using define() directive, like define ("MYCONSTANT",150)

What Is a Session?

It can be used to store information on the server for future use

How to set cookies in PHP?

Cookies are often used to track user information

Syntax:

Setcookie(name, value, expire, path, domain);

eg:Setcookie(“sample”, “ram”, time()+3600);

Difference between mysql_connect and mysql_pconnect?

There is a good page in the php manual on the subject, in short mysql_pconnect() makes a persistent connection to the database which means a SQL link that do not close when the execution of your script ends.

mysql_connect()provides only for the databasenewconnection
while using mysql_pconnect , the function would first try to
find a (persistent) link that's already open with the same
host, username and password. If one is found, an identifier
for it will be returned instead of opening a new connection...
the connection to the SQL server will not be closed when the
execution of the script ends. Instead, the link will remain
open for future use.

How to create a mysql connection?

mysql_connect(servername,username,password);

How to open a file?

<?php
$file=fopen("welcome.txt","r");
?>