Top 29 Lamp Interview Questions You Must Prepare 27.Jul.2024

Q1. What Is Htmlentities And What Is Their Functionality ?

Htmlentities() just converts the characters into HTML entities.

Q2. What Is A Trigger And Does Mysql Support Triggers ?

A trigger is a database object that is associated with a particular table in a database. It gets activated automatically and performs when either INSERT, UPDATE, DELETE action occurs on the table.

MySQL supports triggers from MySQL 5.0.2 version.

Q3. Please State How To Submit A Form Without Using A Submit Button ?

We can submit a form without using a submit button by having a JavaScript code linked to any event trigger of a form field. And just add the code document.form.submit() function to submit the form when the event is triggered.

Q4. What Is Urlencode() And Urldecode() ?

urlencode() converts special characters into characters that are safe to be used in URL’s. Mostly they are converted into % signs along with 2 hex digits.

For ex: urlencode(“20:00%) is converted into “25%2E00%25?”

urldecode() does the opposite and returns the decoded string..

Q5. What Is The Difference Between The Functions Unlink And Unset?

The Unlink() function deletes the file whereas Unset() makes a set variable as undefined.

Q6. How You Will Define A Session ?

A Session is a method to store some data to be used across multiple pages. In technical terms it is a logical object that is stored in the server to help you store data and can be accessed across multiple HTTP requests. Session is always temporary based on the session timeout set in your Apache Server.

Q7. Can You Encrypt Your Password In Php And How To Do It ?

Yes, you can encrypt passwords and all kinds of data in PHP using md5() or sha() functions.

Q8. How Can We Unset The Variable Of A Session ?

With the session_unset($variable_name) function, one can clear the session variable.

Q9. Please State How Can You Take A Backup Of The Whole Database In Mysql ?

You can use the command line utility to take a backup of all the mysql table or a specific mysql table easily with the following:

mysqldump –-user [user_name] –-password=[password] [database_name] > [dump_file_name]

Q10. How You Will Find The Number Of Elements Present In An Array ?

To find the no. of elements in an array, you can either use count() or sizeof() function

Ex:  count($array) or sizeof($array).

Q11. Can You Execute A Php Script In Command Line ?

Yes, we can execute a PHP script in command line with the following command line argument

# php yourscript.php

Where php is the command to execute the php script in a Command Line Interface (CLI)

Q12. State The Main Difference Between Mysql_fetch_array And Mysql_fetch_object ?

Mysql_fetch_array will fetch all the matching records, whereas mysql_fetch_object will only fetch the first record that matches the query.

Q13. Can You Increase The Execution Time Of A Php Script ?

Yes, we can use the max_execution_time variable to set the desired time you needed for executing a php script.

Q14. How Can We Encrypt And Decrypt A Data Present In A Mysql Table Using Mysql ?

To encrypt data in a mysql table, you can use the following: AES_ENCRYPT () and AES_DECRYPT ()

Q15. State The Main Difference Between Mysql_connect And Mysql_pconnect ?

With mysql_connect, you open a database connection each time when the page loads, whereas with mysql_pconnect, connection gets established only once and provides access to the database across multiple requests.

Q16. What Are The Types Of Errors In Php And Explain Each One Of Them ?

The types of errors in PHP are Notices, Warnings & Fatal Errors.

Notices are less important errors that you don’t want to give much importance to it. Like errors that occur, when you try to access a variable that is not defined. If you change the notice errors to be not displayed, you won’t see these kinds of errors at all.

Warnings are errors of some serious nature that demand your attention. Even though these errors are displayed to the user, the script will not terminated. Example of this error includes accessing a file that doesn’t exist.

Fatal Errors are mission critical errors that result in immediate termination of your script. Examples of these errors include, calling an object of a non-existent class etc.

Q17. What Is Sql Injection And How Do You Deal With That ?

SQL injection is a technique utilized by hackers to get access into your database by using malicious SQL statements. Using this, anyone can gain complete access to your database without any authorization or permission.

To start with one need to use mysql_real_escape_string() to filter the user input data, before passing onto the sql statement.

Q18. State The Main Difference Between $message And $$message ?

$message is a name of a variable, whereas $$message is a variable with its name stored inside $message.

For example if $message=”var”, then $$message is the same as $var

Q19. Is Php A Case Sensitive Programming Language ?

It is partially case sensitive, where we can use function and class names in case sensitive manner but variables need to be used in a case sensitive manner.

Q20. Can You Increase The Maximum Upload Size In Php ?

Yes, we can use the upload_max_filesize variable to change the maximum size of a file you can upload.

Q21. Please Explain The Output Of The Code Provided Below And Explain The Reasoning ?
$a = 012; Echo $a / 4;

The wer is 2.5.

In PHP, whenever a number is prefixed with 0, it will be considered as an octal number, and hence the 012 octal number is equivalent to the decimal number 10, and so 10/4 is 2.5

Q22. What Php Image Functions Do You Use To Get The Properties Of An Image ?

There are various php images functions that deals with images and you can use:

  • exif_imagetype() – To get the type of the image
  • getimagesize() – To get the size of the image
  • imagesx() – To get the width of the image
  • imagesy() – To get the height of the image

Q23. How Do You Register The Variables Into A Session ?

To register variables in a session, you need to use the session_register() function

Ex: session_register($login_id)

Q24. How To Destroy A Session Variable ?

Session_unregister() Unregister a global variable from the current session

Q25. State The Main Difference Between Require And Include, Include_once ?

The main difference is that when using require, it will throw a fatal error when a file is not found, whereas include and include_once will show a warning and continue to load the page.

Q26. How To Repair A Table In Mysql ?

To repair a table in MySQL you need to use the following query: 

  1. REPAIR TABLE {table name}
  2. REPAIR TABLE {table name}  QUICK / EXTENDED
  3. MySQL will do a repair of only the index tree, If QUICK is given
  4. MySQL will create index row by row, If EXTENDED is given.

Q27. What Is Nl2br() ?

nl2br() function inserts HTML line breaks before each newline in a string.

For example nl2br(“How are you”) will return strings added with HTML line breaks before all new lines in a string, and the output will be like:

How
are
you

Q28. How To Destroy A Cookie ?

You just need to set the cookie to a previous date or time.

Q29. How Can One Handle Loops In Php ?

In PHP, you the looping statements like while, do while, for and for each.