PHP (MCQs)

Q 0. Which of the following is a correct PHP tag? A. <?php ?> B. <? ?> C. <php> D. <% %>

Shw me The Right Answer

Answer. A
Q 1. What does the connect_errno property of a mysqli object indicate in PHP? A. It indicates the error number of the last connection attempt B. It returns the total number of failed connection attempts C. It is a boolean value indicating whether the connection was successful D. It stores the MySQL server version

Shw me The Right Answer

Answer. A
Q.2 What is the main advantage of using prepared statements in PHP for database queries? A. Increased query execution speed B. Reduced memory usage C. Enhanced security against SQL injection attacks D. Simplified syntax

Shw me The Right Answer

Answer. C
Q. 3 Which of the following is an appropriate use of PHP Data Objects (PDO)? A. Connecting to multiple database types B. Creating HTML content C. Parsing JSON data D. Managing PHP sessions

Shw me The Right Answer

Answer. A
Q.4 What does the PHP mysqli_real_escape_string() function do? A. Sanitizes input for use in a SQL query B. Converts special characters to HTML entities C. Encrypts a string D. Splits a string into an array

Shw me The Right Answer

Answer. A
  Q.5 When retrieving data from a MySQL database, which PHP function is used to fetch a row as an associative array?   A. mysqli_fetch_assoc() B. mysqli_fetch_array() C. mysqli_fetch_row() D. mysqli_fetch_all()

Shw me The Right Answer

Answer. A
Q.6 In PHP, which function is used to execute a SQL query against a MySQL database? A. mysql_query() B. mysqli_query() C. execute_sql() D. run_query()

Shw me The Right Answer

Answer. B
Q.7 Which PHP function is used to connect to a MySQL database? A. mysql_connect() B. mysqli_connect() C. connect_db() D. db_connect()

Shw me The Right Answer

Answer. B
Q.8 Spot the error in the following PHP form handling code: if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) { echo $_POST[name]; } ?> A. Missing quotes around array key name B. No error in the code C. Syntax error in if statement D. Missing semicolon in echo statement

Shw me The Right Answer

Answer. A
Q.9 Identify the issue in this PHP code for handling a form input: if (isset($_GET[‘submit’])) { echo $_POST[‘name’]; } ?> A. Incorrect use of $_GET and $_POST B. No issue C. Syntax error D. The input name should be ‘submit’ instead of ‘name’

Shw me The Right Answer

Answer. A

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments