Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which version of PHP introduced the visibility keywords i.e public, private, and protected?(a) PHP 4(b) PHP 5(c) PHP 5.1(d) PHP 5.3This question was addressed to me in an online interview.My question is from Object Basics-1 topic in portion Objects and Databases in PHP of PHP

Answer»

Correct choice is (b) PHP 5

The EXPLANATION is: In PHP 4, all properties were declared with VAR keyword, which is identical in effect to using public. For the SAKE of backward COMPATIBILITY, PHP 5 accepts var in place of public for properties.

52.

Fill in the blank with the best option. An Object is a/an ________ of a class.(a) type(b) prototype(c) instance(d) objectThe question was asked during an online exam.The origin of the question is Object Basics-1 in chapter Objects and Databases in PHP of PHP

Answer»

Right answer is (c) INSTANCE

Best explanation: An OBJECT is SAID to be an instance of its class. It is of the type DEFINED by the class.

53.

Which one of the following is not a valid class name?(a) ShopProduct(b) Shopproduct(c) Shopproduct1(d) 1shopproductI had been asked this question by my school principal while I was bunking the class.Origin of the question is Object Basics-1 in division Objects and Databases in PHP of PHP

Answer»

Right CHOICE is (d) 1shopproduct

To elaborate: You declare a class with the class keyword and an arbitrary class name. Class names can be any combination of numbers and letters, although they must not BEGIN with a NUMBER.

54.

Which method retrieves each row from the prepared statement result and assigns the fields to the bound results?(a) get_row()(b) fetch_row()(c) fetch()(d) mysqli_fetch_row()This question was posed to me in an international level competition.Enquiry is from Working with Databases-2 topic in portion Objects and Databases in PHP of PHP

Answer»

Correct ANSWER is (d) mysqli_fetch_row()

Explanation: The function mysqli_fetch_row() is used to fetche ROW from a RESULT-set and returns it as an enumerated array.

Its syntax is mysqli_fetch_row(result);

55.

Which method rolls back the present transaction?(a) commit()(b) undo()(c) mysqli_rollback()(d) rollback()The question was posed to me in a job interview.My question comes from Working with Databases-2 topic in section Objects and Databases in PHP of PHP

Answer»

The correct OPTION is (c) mysqli_rollback()

The explanation: The function mysqli_rollback() is used to ROLL back from the current transaction for the specified database CONNECTION. Its syntax is: mysqli_rollback(connection);

Rollback() was used in PREVIOUS version of PHP.

56.

Which one of the following methods is used to recuperating prepared statements resources?(a) end()(b) finish()(c) mysqli_close()(d) close()This question was addressed to me by my school principal while I was bunking the class.I need to ask this question from Working with Databases-2 in portion Objects and Databases in PHP of PHP

Answer»

Right option is (c) mysqli_close()

The explanation: The FUNCTION mysqli_close() is used to CLOSE an opened database connection. Once you’ve finished using a PREPARED statement, the resources it requires can be recuperated with the mysqli_close() method. Close() was used in PREVIOUS version of PHP.

57.

Which of the following methods is used to execute the statement after the parameters have been bound?(a) bind_param()(b) bind_result()(c) bound_param()(d) bound_result()I had been asked this question during an internship interview.My doubt is from Working with Databases-2 in portion Objects and Databases in PHP of PHP

Answer»

Correct option is (a) bind_param()

The explanation: Once the statement has been prepared, it NEEDS to be executed. Exactly when it’s executed depends upon WHETHER you WANT to work with BOUND parameters or bound results. In the case of bound parameters, you’d execute the statement after the parameters have been bound with the bind_param() method.

58.

Which version of MySQL introduced the prepared statements?(a) MySQL 4.0(b) MySQL 4.1(c) MySQL 4.2(d) MySQL 4.3This question was addressed to me during an interview.I would like to ask this question from Working with Databases-2 in section Objects and Databases in PHP of PHP

Answer»

The correct option is (b) MYSQL 4.1

To explain I would say: When the query() method is LOOPED repeatedly it comes at a cost of both overhead, because of the NEED to repeatedly parsing of the almost identical query for validity, and CODING convenience, because of the need to repeatedly reconfigure the query using the new values for each iteration. To help resolve the issues incurred by repeatedly executed queries, MySQL INTRODUCED prepared statements.

59.

Which one of the following method is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE query?(a) num_rows()(b) affected_rows()(c) changed_rows()(d) mysqli_affected_rows()This question was posed to me in my homework.I want to ask this question from Working with Databases-2 in portion Objects and Databases in PHP of PHP

Answer»

The correct option is (d) mysqli_affected_rows()

Easy explanation: The method mysqli_num_rows() is only useful for determining the number of ROWS RETRIEVED by a SELECT QUERY. But to retrieve the number of rows affected by INSERT, UPDATE, or DELETE query, use mysqli_affected_rows(). Num_rows() andaffected_rows() were used in previous version of PHP.

60.

Which one of the following methods recuperates any memory consumed by a result set?(a) destroy()(b) mysqli_free_result()(c) alloc()(d) free()I have been asked this question in my homework.I need to ask this question from Working with Databases-2 topic in portion Objects and Databases in PHP of PHP

Answer»

The CORRECT answer is (B) mysqli_free_result()

Easiest explanation: The function mysqli_free_result() is USED to free the memory which is associated with the result. Once this method is executed, the result set is no longer AVAILABLE. Free() function was used in the previous version of PHP.

61.

Which one of the following statements should be used to include a file?(a) #include ‘filename’;(b) include ‘filename’;(c) @include ‘filename’;(d) #include ;This question was addressed to me in my homework.Asked question is from Working with Databases-2 in portion Objects and Databases in PHP of PHP

Answer» CORRECT choice is (b) include ‘FILENAME’;

The explanation is: Include in PHP will takes all the code from the specified FILE and copies to the existing file containing include statement. An example of this-
62.

Which of the methods are used to manage result sets using both associative and indexed arrays?(a) get_array() and get_row()(b) get_array() and get_column()(c) fetch_array() and fetch_row()(d) mysqli_fetch_array() and mysqli_fetch_row()This question was posed to me in semester exam.I need to ask this question from Working with Databases-2 in portion Objects and Databases in PHP of PHP

Answer» RIGHT ANSWER is (d) mysqli_fetch_array() and mysqli_fetch_row()

EASIEST explanation: The method mysqli_fetch_array() is used to fetch a RESULT row as an associative array or a numeric array.

And the function mysqli_fetch_row() is used to fetche one row from a result-set and returns it as an enumerated array.

The method fetch_array() and fetch_row() were used in the previous version of PHP.
63.

Which one of the following methods is responsible for sending the query to the database?(a) query()(b) send_query()(c) sendquery()(d) mysqli_query()The question was asked in an online quiz.I want to ask this question from Working with Databases-2 in section Objects and Databases in PHP of PHP

Answer»

Right choice is (d) mysqli_query()

To explain I would say: The METHOD mysqli_query() is responsible for SENDING the query to the database. Query() method was previously USED in older versions of PHP.

64.

If there is no error, then what will the error() method return?(a) TRUE(b) FALSE(c) Empty String(d) 0This question was posed to me by my college professor while I was bunking the class.My doubt is from Working with Databases-1 in division Objects and Databases in PHP of PHP

Answer» RIGHT choice is (C) Empty String

The BEST explanation: The function error is used to deal with error handling and logging. If there is no error, then the error() METHOD will RETURN an empty string.
65.

Which method returns the error code generated from the execution of the last MySQL function?(a) errno()(b) errnumber()(c) errorno()(d) errornumber()I have been asked this question in unit test.My query is from Working with Databases-1 topic in section Objects and Databases in PHP of PHP

Answer»

Correct answer is (a) errno()

EXPLANATION: Error numbers are often USED in lieu of natural-language message to ease software INTERNATIONALIZATION efforts and ALLOW for customization of error messages.

66.

Which one of the following methods can be used to diagnose and display information about a MySQL connection error?(a) connect_errno()(b) connect_error()(c) mysqli_connect_errno()(d) mysqli_connect_error()This question was posed to me in my homework.This question is from Working with Databases-1 in division Objects and Databases in PHP of PHP

Answer»

Right ANSWER is (C) mysqli_connect_errno()

To explain: The mysqli extension includes a few features that can be used to capture ERROR messages or alternatively you can USE exceptions.

67.

Which one of the following statements can be used to select the database?(a) $mysqli=select_db('databasename');(b) mysqli=select_db('databasename');(c) mysqli->select_db('databasename');(d) $mysqli->select_db('databasename');I got this question in an interview for job.This is a very interesting question from Working with Databases-1 in chapter Objects and Databases in PHP of PHP

Answer»

The CORRECT OPTION is (d) $mysqli->select_db('DATABASENAME');

To explain I would say: $mysqli->select_db(‘databasename’); can be used to select the DATABASE.

68.

Which one of the following statements instantiates the mysqli class?(a) mysqli = new mysqli()(b) $mysqli = new mysqli()(c) $mysqli->new.mysqli()(d) mysqli->new.mysqli()The question was posed to me during an online interview.Origin of the question is Working with Databases-1 topic in chapter Objects and Databases in PHP of PHP

Answer»

Right choice is (B) $mysqli = new mysqli()

Best explanation: If you CHOOSE to INTERACT with MySQL SERVER using the object-oriented INTERFACE, you need to first instantiate the mysqli class via its constructor.

69.

Which one of the following statements is used to create a table?(a) CREATE TABLE table_name (column_name column_type);(b) CREATE table_name (column_type column_name);(c) CREATE table_name (column_name column_type);(d) CREATE TABLE table_name (column_type column_name);This question was posed to me during an interview for a job.My enquiry is from Working with Databases-1 in chapter Objects and Databases in PHP of PHP

Answer»

The correct option is (a) CREATE TABLE table_name (column_name column_type);

To explain: The example creates a table CALLED “student” that CONTAINS five columns: SID, LastName, FirstName, Address, and City:

70.

In which version of PHP was MySQL Native Driver(also known as mysqlnd) introduced?(a) PHP 5.0(b) PHP 5.1(c) PHP 5.2(d) PHP 5.3I got this question in an interview for job.The origin of the question is Working with Databases-1 topic in chapter Objects and Databases in PHP of PHP

Answer»

Correct option is (d) PHP 5.3

The explanation: PHP required that MYSQL client LIBRARY be installed on the server from which PHP was communicating with MySQL, whether the MySQL server also HAPPENED to reside locally or elsewhere. PHP 5.3 removes this problem by introducing MySQL NATIVE Driver.

71.

Which one of the following lines need to be uncommented or added in the php.ini file so as to enable mysqli extension?(a) extension=php_mysqli.dll(b) extension=mysql.dll(c) extension=php_mysqli.dl(d) extension=mysqli.dlI have been asked this question in exam.My question is based upon Working with Databases-1 topic in chapter Objects and Databases in PHP of PHP

Answer»

Right answer is (a) extension=php_mysqli.dll

Easiest explanation: ALSO MAKE sure that extension_dir directive points to the APPROPRIATE DIRECTORY.

72.

Which one of the following databases has PHP supported almost since the beginning?(a) Oracle Database(b) SQL(c) SQL+(d) MySQLI had been asked this question in an online quiz.The doubt is from Working with Databases-1 topic in section Objects and Databases in PHP of PHP

Answer»

Correct CHOICE is (d) MYSQL

The best explanation: We can connect, insert, UPDATE, delete and retrieve data from the databases with the help of PHP and MySQL is the most popular database system used with PHP.

73.

The updated MySQL extension released with PHP 5 is typically referred to as _______________(a) MySQL(b) mysql(c) mysqli(d) mysqlyI got this question during an internship interview.My doubt stems from Working with Databases-1 topic in section Objects and Databases in PHP of PHP

Answer» RIGHT ANSWER is (C) mysqli

Explanation: The updated MySQL EXTENSION with PHP 5 is known as MySQL and typically REFERRED to as mysqli.
74.

Parameter flags was added in which version of PHP?(a) PHP 4.0(b) PHP 4.1(c) PHP 4.2(d) PHP 4.3The question was posed to me in an online interview.Question is taken from Introduction to Preg in PHP topic in portion Objects and Databases in PHP of PHP

Answer»

Correct option is (d) PHP 4.3

For explanation: PARAMETER FLAGS was added in PHP 4.3 VERSION.

75.

Which one of the following is not a preg PHP function?(a) preg_match(b) preg_match_all(c) preg_matchall(d) preg_splitThis question was posed to me by my college director while I was bunking the class.Asked question is from Introduction to Preg in PHP in division Objects and Databases in PHP of PHP

Answer» CORRECT OPTION is (c) preg_matchall

The explanation: The function preg_match_all() MATCHES all occurrences of pattern in STRING.
76.

Which one of the following preg PHP functions is used to take a string, and put it in an array?(a) preg_destroy()(b) preg_split()(c) preg_unchain()(d) preg_divide()The question was asked in semester exam.Enquiry is from Introduction to Preg in PHP topic in division Objects and Databases in PHP of PHP

Answer»

Right ANSWER is (b) preg_split()

For explanation: The string is broken up into different VALUES in the ARRAY based UPON your INPUT.

77.

Which one of the following preg PHP function is used to do a find and replace on a string or an array?(a) preg_replace()(b) preg_find()(c) preg_find_replace()(d) preg_findre()I had been asked this question in class test.Asked question is from Introduction to Preg in PHP topic in chapter Objects and Databases in PHP of PHP

Answer» CORRECT choice is (a) preg_replace()

The best I can EXPLAIN: In preg_replace() FUNCTION, after the replacement has occurred, the modified STRING will be returned and if no matches are found, the string will REMAIN unchanged.
78.

Which one of the following functions are used to search a string?(a) preg_match(b) preg_search(c) preg_find(d) preg_foundThe question was asked by my school principal while I was bunking the class.I'd like to ask this question from Introduction to Preg in PHP in chapter Objects and Databases in PHP of PHP

Answer» CORRECT choice is (a) preg_match

Explanation: The function preg_match() searches string for PATTERN and it returns true if pattern EXISTS, and false otherwise. The function returns 1 if SEARCH was SUCCESSFUL else returns 0.
79.

What will be the output if we replace the line $num = preg_grep(“/[0-5]/”, $number); with $num = preg_grep(“/[0-5]/”, $number, PREG_GREP_INVERT);?(a) Array([0]=>0 [1]=>1 [2]=>two [3]=>three [4]=>four [5]=>5)(b) Array([2]=>two [3]=>three [4]=>four)(c) Array([1]=> 1)(d) Array([0]=>0 [5]=>5)I have been asked this question by my school teacher while I was bunking the class.This question is from Introduction to Preg in PHP in section Objects and Databases in PHP of PHP

Answer»

Right CHOICE is (b) Array([2]=>two [3]=>THREE [4]=>four)

To elaborate: When we include PREG_GREP_INVERT, this will invert our data, so instead of OUTPUTTING NUMBERS it will output our non-numeric VALUES.