Friday 14 April 2017

php interview Question with answer

An    Interview , in   PHP . best he answered

Raj  is having  well hands-on experince in php , He  is getting into php technical interview round

 Interviewer started  by asking .

 "  What are different  areas , where  PHP  can be used ?"

Raj replied :

     There are three main areas where PHP scripts are used.

              1. Server-side scripting :  Php  run on  the web server, with a connected PHP installation. You can access the PHP program output with a web browser .

      2. Command Line Scripting : PHP Script will  also  run without any server or browser with help of  PHP parser .
            3 . Writing desktop applications : PHP can also  be used  to create a desktop application with a  graphical user interface .We can  use PHP-GTK  to write such programs.

Interviewer : 

 "Explain file handling in php  and all  their diffrent operation   like(reading , writing updating etc..)in detail"

Raj replies : 

PHP has several functions for     Creating,    Reading,    Open and Closing    and Editing Files.

PHP readfile() Function  , The readfile() function reads a file and  writes  it to the output buffer. Example is given below

  PHP Open File - fopen() . A better method to open files is with the fopen() function. This function gives you more options than the readfile() function.Example is given below.
  PHP Read File - fread().  The fread() function reads from an open file.  The first parameter of fread() contains the name of  the file to read from and the second parameter specifies the maximum number of bytes to read. Example is given below

     PHP Close File - fclose(). The fclose() function is used to close an open file. Example  is given below.

   PHP Read Single Line - fgets() . The fgets() function is used to read a single line from a file. Example is given below

PHP Check End-Of-File - feof(). The feof() function checks if the "end-of-file" (EOF) has been reached.Example is given below

PHP Read Single Character - fgetc() .The fgetc() function is used to read a single character from a file. Example is given below.

PHP Write to File - fwrite() .The fwrite() function is used to write to a file.Example is given below

Interviewer next question :

"Whats the difference between mysql_connect  and  mysql_pconnect  ?"

Raj Replied : 

mysql_connect - Open a connection to a MySQL Server. Connection will be closed as soon as the execution  of the script ends, unless it's closed earlier by  explicitly calling mysql_close().Example  is given below.

While mysql_pconnect   Establishes a persistent connection to a MySQL server. When a persistent connection is requested,  PHP checks if there's already an identical persistent  connection (that remained open from earlier) - and if it exists, it uses it.
Example is given below.

Interviwer next question :

Explain PHP MySql functions :  mysql_fetch_array , mysql_fetch_assoc ,  mysql_fetch_row , mysql_fetch_object and their  differences.

Raj replied :

mysql_fetch_array    Fetch a result row as an associative array, a numeric array, or both

     mysql_fetch_array ( resource $result [, int $result_type = MYSQL_BOTH ] ) 
result_type is a constant and can take the following values: 

Example is given below.

mysql_fetch_assoc    Fetch a result row as an associative array 

mysql_fetch_assoc ( resource $result )

Example  is given below

mysql_fetch_row    Fetches one row of data from the  result associated with the specified result identifier. The row is returned as an array.  

mysql_fetch_row ( resource $result )

Example is given below

 mysql_fetch_object    Fetch a result row as an object 
mysql_fetch_object( resource $result )

Example is given below 

Interviewer next question :

 What is difference between COOKIES  and SESSION. Explain both.

Raj replied :

   A COOKIE is a small piece of text stored on a user's  computer by their browser. Each time the users' web browser interacts with a web server  it will pass the cookie information to the web server.

This means that cookies that relate to will not be sent  to
   Common uses for COOKIES are authentication, storing of site preferences, shopping cart items,and server session identification.

 A SESSION can be defined as a server-side storage of  information that is desired to persist throughout the  user's interaction with the web site or web application. 

Instead of storing large and constantly changing  information via COOKIES in the user's browser, only a unique identifier is stored on the client side  (called a "session id(SSID)"). 

This session id is passed to the web server every time  the browser makes an HTTP request (ie a page link or AJAX request). 

The web application pairs this session id with it's internal database and retrieves  stored variables for use by the requested page.

Interviewer  next question :

 What is Sql injection and how  it can be prevented? 

Raj replied:

 SQL Injection is the placement of malicious code in SQL statements, via web page input.

             SQL Injection is one of the most common web hacking techniques.

  For Example The original purpose of the below code was to create  an SQL statement to select a user, with a given user id.

 If there is nothing to prevent a user from entering "wrong" input, the user can enter some "smart" input  like this: , UserId: 105 OR 1=1

Then, the SQL statement will look like this: , SELECT * FROM Users WHERE UserId = 105 OR 1=1; 

 The SQL above is valid and will return ALL rows from the "Users" table, since OR 1=1 is always TRUE.

 A hacker might get access to all the user detail,  that will be very dangerous.


 SQL Injection  can prevented by  using
       (1). mysqli_real_escape_string

     The mysqli_real_escape_string() function escapes  special characters in a string for use in an SQL statement.     

 Another way preventing SQL Injection  is by  using
  using prepared statment

     Example is given below 

Interviewer  next question :

What is   CrossSite  Scripting ?

Raj replied:

Cross-Site Scripting (XSS) attacks are a type of  injection, in which malicious scripts are injected into   trusted web sites. 
        Example is given below 

The end user’s browser has no way to know that the script should  not be trusted, and will execute the script , because it thinks the script came from a trusted source, the malicious script can access any cookies, session tokens, or other sensitive information retained by the browser and passes  to attcker  . 
          These scripts can even rewrite the content of the HTML page. 
 Example is given below

Interviewer   Next Question :

Explain  Rest Services .

Raj replied :

REST defines a set of architectural principles by which you can design Web services that focus on a system's resources, including how resource states  are addressed and transferred over HTTP by a wide range of clients written in different languages.

REST Web service follows four basic design principles:
    * Use HTTP methods explicitly.
    * Be stateless.
    * Expose directory structure-like URIs.
    * Transfer XML, JavaScript Object Notation (JSON), 
           or both.

Interviewer next question :

Explain  SOAP.

Raj replied :

 SOAP  stands for Simple Object Access Protocol.

SOAP provides the envelope for sending  Web Services messages over the Internet/Internet.  It is part of the set of standards specified by      the W3C

The SOAP envelope contains two parts:

*  An optional header providing information on authentication,   encoding of data, or how a recipient of a     SOAP message should process the    message.

*  The body that contains the message. These messages can be defined using the WSDL specification.

Interviewer  next question

 What is difference  between include  and require ?

Raj replied:

With the include or require statement. We used to insert the content of one PHP/html file into  another PHP file (before the server executes it)

    In  include - (if source file missing it'll give warning    and continue execution),    while in require - (if source file missing it'll give         error  and halt execution),)

      With the include or require statement. We used to insert the content of one PHP/html file into  another PHP file (before the server executes it)

      In  include - (if source file missing it'll give warning    and continue execution),    while in require - (if source file missing it'll give  error  and halt execution),)

Interviewer Next Question :

Explain session_set_save_handler   ?

Raj replied :

To maintain the session data, we can use session_set_save_handler function.

This function provide 6 callback functions which call automatically.

   openFunction will be called automatically when session start.
   closeFunction will be called automatically when session end.
    readFunction will be called automatically when you read the session.
  writeFunction will be called automatically when you write in the session.
  destroyFunction will be called automatically when you destroy in the session.
   gcFunction will be called automatically when session inactive for long time.

Interviewer Next Question :

 How to convert string to array   and array to string in php?

Raj replied:

 Explode convert string to array ,   example given below

Implode convert array to string   ,    example given below


Interviewer  Next Question :

  How to scrape the data from website using CURL?

Raj replied :

 To scrap the data from website, Website must be  public and open for scrapable. In the blow code, Just update the CURLOPT_URL  to which websites data you want to scrap.

Interviewer Next Question :

How to explode a string using multiple delimiters("," and "|" )?

Raj replied:

  To explode a string with multiple delimeters , we use preg_split

 $string='php, interview | questions , and | answers ';
$output = preg_split( "/(\,|\|)/", $string );
print_r($output );

  Raj replied to  all question    very well


Thursday 6 April 2017

Strengths and weaknesses asked in interview

Strengths and Weakness  Asked in Interview

This is another most common question asked by Interviewer.This question is asked to know whether :

* Candidate does have those qualities which are required by the company and for particular job.

Similarly weakness to know in which area you are lacking.
*Aren’t your weakness harm the job.

Let’s see how to answer this question.

Lalit is one interviewee who has gone for interview 

. Interviewer asked him
    "what are your strengths and weaknesses?"


"My strengths are:
·       I am having very good communication skills.
·       I have excellent presentation skills.
·       I can work with diverse group of people.
·       I am a very good team player.   "

Hmm…is this the right way to answer this question  ?


Lalit has clearly mentioned about his strengths, that’s good.

That’s good but how recruiter would come to know, lalit actually practiced these strengths.

Then what should he do?

He should substantiate at least 2 strengths briefly to interviewer, not all as it will stretch the interview or explain that one which interviewer wants to know. 

Let’s see again how Lalit answer the question for strengths.

Interviewer:  "what are your strengths and weakness?"

Lalit :  My strengths are: 

" I am having very good communication skills (as I headed student’s editing team of my college magazine plus hosted various college programme), with excellent presentation skills, I can also work with diverse group of people, (during my internship in Master’s which I did in retail; I worked closely from Area sales manager to store security Guard. I need to train whole staff of retail store which also includes helpers and security Guards. I maintain very healthy relationship with all). I am a very good team player plus hard worker.  "

Now we have seen how Lalit described only two strengths to interviewer with mixing other strengths.

Try to highlight those strengths which are directly related to your job or suit the requirement of job. Example:

Sales profile job’s require:
·       good communication
·       Person who likes to meet new people
·       Like to travel etc.

But it doesn’t mean you start lying plus also sounds like a scripted robot. Be natural answer as a conversation, because an interview is also a conversation

Now we see how Lalit told his weakness.

Interviewer: " good, What about weaknesses?"

Lalit: " Mam! Rather calling these are my weaknesses, I would say these are my areas of improvements. Like I am slightly impatience regarding my work, as I want my all work perfect so I am working on it to be clam, I also want to learn to say no, by saying yes to everyone I burden myself with work which leads to stress at last I am not able delegate the work which again piled up work on me which hampers my work style. So these are the areas of improvement, I require."

"Well! Lalit these are not seems as weaknesses while showing you as a workaholic, it’s good for companies but you should balance it. It’s nice talking to you.  Wait for some time for result. "

What do you think? 

 Lalit has answered very well about weaknesses.  

Firstly he stated weaknesses as a area of improvement which every interview should say while answering this question. 

Secondly he stated all his work positive weaknesses which actually are requirement of any company. That’s why interviewer said you are workaholic.

 What did this mean?

 Telling weaknesses are not being completely open yourself in front of interviewer while smartly module your answer in a positive way, so that it shows you positive in front of interviewer. 

Sunday 26 March 2017

Interview Tips for trainer , Complete Interview and key points of interview

*       Position: Trainer
*       Work experience: Fresher

*       Education Qualification: Graduation/Post- Graduation.

This is an interview of a person who got selected as a trainer in skill development sector in one of the big brand of education industry.

(Fresher’s interviews totally depend on their curriculum vita and their qualification because a fresher doesn’t have any work experiences, so his /her qualification is the only experience he/she is carrying. It’s better to mention true and documented proof which he/she is having with them. Plus don’t mention any information, which one don’t have any knowledge or idea, it may lead to rejection.)

      Candidate ,  Good Morning Sir .
      Interviewer: Good Morning. How are you?

      Interviewee: I’ am fine Ma’am and you?

      Interviewer: All good, let’s start with the process. So tell me about yourself?

      Interviewee: My name is Ram. I completed my MBA from ABC Institute and did my graduation from DEF university. My schooling was from QRS School Delhi. I live in South Delhi and I am fresher. 

      Interviewer:  what you did in graduation?

      Interviewee: I did B.A

      Interviewer:  Was your college regular?
      Interviewee:  Yes, I my college was regular.

      Interviewer:  you have mentioned in your C.V that you did internship in the retail sector. Can you tell me about this internship?

      Interviewee:  Yes, I did my internship in the retail sector in marketing field.  Where I need to do marketing, research and merchandising of XYZ Company’s product.

(This answer must be depending on projects or trainings mentioned by candidate on the resume. Candidate must have full knowledge of mentioned projects or training with full documented proof.)

      Interviewer:  You said, you were taking care of marketing of product of XYZ Company. Then why do you want a job in training field? Not in marketing field?

      Interviewee:  The reason behind this, I want to do job in training field because I like training, it is a very interesting field and you need to learn a lot every day, it’s very vibrant field and I love training.

      Interviewer: It seems you like training job. This very good for us. Now let me ask some basic questions related to training? What is the difference between training and teaching?

      Interviewee: There is one difference between training and teaching, which is a methodology. Teaching mainly follows pedagogy while training follows andragogy.  So it’s depending where teaching is required and where training is required.

      Interviewer: Good answer. If you got selected in our company then you need to train students who are mainly from low income group or below the poverty line or school dropouts. Most students are not interested in studies? How will you encourage learning in them or create interest?

      Interviewee:  I need to find out why it happened or why they are not interested in studies. I need to find ways in which they find the studies interesting. They need to be aware or counsel, why studies are important. 

(Every interview has technical round on which candidate’s selection is judge, so one should brush the learning or knowledge required for job. It is must.)

      Interviewer: If any student gets dropped out or stop coming to your classes. What will you do? How you’ll bring her/him back?

      Interviewee:  If this kind of case will happen, I will go to the student and ask why he/she has stopped coming to my class? What are the reasons? And then I will counsel him/her according to that and try my best to get her/him back to my class.

      Interviewer: Good answer ram. Tell me your strengths and weaknesses?

      Interviewee: My strengths are I am hard working. I used to work late night or early morning on my projects in my masters, that’s why I got excellence certificates in my projects and I am an empathetic person, that’s why I help people going beyond my strength, due to this I am also a good team player. Now my weaknesses are: I am an impatient person, I can’t take rest till my work is not completed plus I am a very aggressive person, I want my things in the right way till it’s not harming anyone.  

(This answer is also matter of subjective but its best to mention his/her strengths and weaknesses by keeping job or position in mind)

      Interviewer: Well, good we need an empathetic person who understands the problem with solutions and a good team player. How soon you can join us?

      Interviewee:. Ma’am, I can join as per your requirement. I am comfortable in that

      Interviewer:  what are your salary expectations?

      Interviewee:  (Answer should be according to salary bar provided by the company or its matter of subjective expectation.)
At the End here the tips to improve your Training skills for getting selection during Demo sessions because in training profile Demo session is main session on which 80% of selection and remuneration depends.

Here are few tips by which one can give effective training:
·       As you know the area of expertise of yours in which you give training so, it’s best you should prepare some topics really well.
·       Try to judge the audiences to whom you impart training by asking some simple questions, like you can ask them what they have studied in their last session.
·       Always state motive or outcome of session before starting the training.
·       Make training session interesting by keeping balance of activities and content, too much of any part can dilute the purpose of training. Example: try to make session interactive.
·       Highlight the main points or sub topics of the training repeatedly during session so those trainees remember the main points of training.
·       Don’t make your training session too long or too short so that it can’t lose its jest.

·         Keep small test at the End of session to know how much trainees have learnt and how effectively you able to impart training plus it’s also make trainee serious throughout training.

·       Always remember two very important things to do at last, first always summaries the learning of training and secondly take feedback to know your positive and improvement points.

Keep these points in practice and in mind for effective training.
                                                Thank you!

Search Any topic , section , query