100 PHP’s possible interview questions and answers for fresher-part 2

  • Home -
  • 100 PHP’s possible interview questions and answers for fresher-part 2

21) How can you get image height and width for any image in PHP?

getimagesize() is used to get image size and imagesx() to fetch image width and imagesy() to fetch height.

22) What is difference between require and include function in PHP?

Both the functions,’require’ and ‘include’ are used to include the files in PHP. However If the file does not exists in server then require throws fatal error and code executions is terminated. On the other hand, if file is not found and include function is used, it throws warning and rest of the code still continues to execute.

23) What is the difference between require() and require_once()?

Both functions require and require_once are used to include file in PHP page, but the difference is that reurie_once checks if the file is already included or not. If yes then it shows warning.

24) What is print_r() used for?

print_r() is used to display the content of any array.

25) ‘Maximum execution time exceeded.’ How can you solve this problem?

We can solve this problem by two ways. Either we can include ‘set_time_limit(time here)’ at the beginning of PHP page.
Or if the php.ini file is accessible, we can increase ‘maximum_execuation_time’ from there also.

26) How can you supress error in PHP?

There is a function called error_reporting() where we can decide if we want to display error or supress it. We write error_reporting(0) . That means all warnings, notices and errors will be supressed. However if we want to display error only, and not notices and warning then we can write error_reporting(E_ERROR).

27) What is use of‘explode’ and ‘split’ functions?

explode() function convert any string with delimiter into Array.Explode is used to split a string using another string.
Example :explode (” this”, “this is a string”); //will return “Is a string”

The split() function splits the string into an array using a regular expression and returns an array.
Example :split(‘:India:Pakistan:Srilanka’);
Returns and array
Explode Example:explode(‘and’,‘India and Pakistan and Srilanka’);
Returns and array

28) What is the function file_get_contents() used for?

file_get_contents() is used to extract the html code of other file and then it is stored in a string format in any variable.

29) What is difference between MySql and MySqlidatabases?

MySql is an old database engine whereas MySqli is the improved database engine. ‘i’ means improved. MySqli supports prepared statement which prevents SQL injection for hackers.

30) What is difference between mysql_connect and mysql_pconnect() useful for?

Both, mysql_connect and mysql_pconnect() are used for database connection but the difference is that mysql_connect closes database connection once the PHP code is executed .On the other hand,mysql_pconnectensures a persistent connection to the database, that means the connection is still on even if the code is executed.

Mysql_pconnect is deprecated and is not supported by php 7.0 and above.

31) What are different ways of getting result set in PHP?

There are following ways of result set ‘mysqli_fetch_array’, ‘mysqli_fetch_assoc’, ‘mysqli_fetch_object’ or ‘mysqli_fetch_row’.

32) What is the function of PHP through which you can count the number of rows returned.

The function mysqli_num_rows() returns the number of rows in a result set.

33) Which keyword is used to get unique values in MySQL records?

‘DISTINCT’ keyword is used to eliminate duplicate values and show only the unique records.

34) What is the difference between mysqli_fetch_object() and mysqli_fetch_array()?

The mysqli_fetch_object() function returns the first single matching record on the other handmysqli_fetch_array() returns all matching records from the table in an array.

35) What are the main difference between GET and POST?

GET and POST are two methods to send data. But the main difference is that data sent through get method is passed via URL and is visible to all. Whereas, data posted using POST method is sent hidden and is not visible to anyone.

36) How post method works?

In the post method, field names and its values are clubbed together to form an associative array and the data is sent to server in the form of Associative array.

37) What is primary and Unique keys in MySqli?

Primary key is a ‘constraint’ in which no duplicate and no null values are allowed. Unique key is also same but it can accepts one null value.

38) How can we check the value of a given variable is alphanumeric?

PHP has built in function for this to check whether the given number is alphanumeric. The function name is ctype_alnum to check whether it is an alphanumeric value or not.

39) What is the function for file upload in PHP?

To upload Image or any file, there is built-in PHP function called move_uploaded_file()
It takes two parameters. The first parameter is files temp name and in the second parameter the actual file name along with the folder name.

40) What does the unlink() function mean?

The unlink() function is used to delete file from server.