Pageviews

Tuesday 28 July 2020

+2].10-Server Side Scripting Using PHP Previous Questions Chapter wise


                           
                                            PLUS TWO  COMPUTER SCIENCE


                               Second Year Computer Science Previous Questions Chapter wise

                                                  Chapter 10.Server Side Scripting Using PHP

1. PHP is

 (a) freeware

 (b) proprietary 

(c) both

 (d) none 

   Ans.  a

2. (a) Compare Indexed and Associative arrays in PHP. 

 (b) Write a PHP program to display prime numbers below 50.

 (c) Write a PHP program to display the perfect numbers below 100. 

  Ans. a) Arrays  with numeric index are called indexed arrays.They use non negative integers as keys.These  arrays can store numbers,strings and any object but their index will be represented by numbers. The function array() can be used to create an array.

         Arrays with named keys are called associative arrays.These are very similar to numeric arrays in terms of functionality but  they are different in terms of their index.

  b.

<?php
    for($i = 1; $i <= 50; $i++)
      $mm = 0;
      for($j = 2; $j <= $i/2; $j++) {
        //only not prime numbers
                if ($i % $j == 0) {
                  $mm++;
                  break;
                }
      }
      if ($mm == 0) {
                echo"$i is prime number<br/>";
      }
    }
  ?>
 c.
<?php

($number % $n)

 { $d += $n; 

if ($n <> $number / $n)

 $d += $number / $n; 

}

 }

 return ++$d == $number;

 } // * example use - display perfect numbers below 100 * // 

for ($n = 1; $n < 100; $n++)

 if (is_perfect($n))

 echo $n . '<br />'; 

?>

        
 3. An array in PHP is given as follows: $family = array(“Father”=>”Ajay”, “Son”=>”Arjun”, “Daughter” =>”Archana”).
 Name the type of this array. Write a for each loop that prints all the array elements.

 4. (a) What are the differences between GET and POST methods in form submitting? 

  Ans. 
          Ans. The two methods are distinct where GET method adds the encoded data to the URI while in case of POST method the data is appended to the body rather than URI. Additionally, GET method is used for retrieving the data. Conversely, POST method is used for storing or updating the data.

(b) Study the following steps and determine the correct order: 

  1. Open a connection to MySQL server 

 (2) Execute the SQL query 

(3) Fetch the data from query. 

(4) Select database 

(5) Close connection 

(a) 4, 1, 2, 3, 5

 (b) 1, 4, 2, 3, 5

 (c) 1, 5, 4, 2, 3

 (d) 4, 1, 3, 2, 5

Ans. b

 5. A web server that supports PHP on any operating system is ____.  

     Ans. WAMP or LAMP or XAMPP

 6. Discuss about special data types used in PHP. 

 Ans.    1. Integer : Integers hold only whole numbers including positive and negative numbers, i.e., numbers without fractional part or decimal point. They can be decimal (base 10), octal (base 8) or hexadecimal (base 16).


2. Double: Can hold numbers containing fractional or decimal part including positive and negative numbers. By default, the variables add a minimum number of decimal places.


3. String : Hold letters or any alphabets, even numbers are included. These are written within double quotes during declaration. The strings can also be written within single quotes but it will be treated differently while printing variables.


4. NULL: These are special types of variables that can hold only one value i.e., NULL. We follow the convention of writing it in capital form, but its case sensitive.


5. Boolean: Hold only two values, either TRUE or FALSE. Successful events will return true and unsuccessful events return false. NULL type values are also treated as false in Boolean. Apart from NULL, 0 is also consider as false in boolean. If a string is empty then it is also considered as false in boolean data type.


6. Arrays: Array is a compound data-type which can store multiple values of same data type. Below is an example of array of integers.


7. Objects: Objects are defined as instances of user defined classes that can hold both values and functions.


8. Resources: Resources in PHP are not an exact data type. These are basically used to store references to some function call or to external PHP resources. For example, consider a database call. This is an external resource.

 7. Create an HTML form in PHP showing the difference between GET and POST method. 

     GET and POST are the values used with Method attribute of tag. The skeleton of the HTML form with these methods will be as follows: .............
.............
When we use GET method, the data remains visible in the address bar since contents are passed as part of the URL. GET can send only 2000 characters. But if we use POST method, the data is not visible as contents are passed to the script as an input file. There is no limit in the size of data.  

8. Write a function in PHP to find the factorial of a number. 


          

 9. Write a PHP program to find the biggest of three numbers. 

          Assume that num1, num2, num3 are the names of the textboxes in the HTML Form submitted to the php program. 

<?php

      $n1 = $_GET[‘num1’];

      $n2 = $_GET[‘num2’]; 

        $n3 = $_GET[‘num3’]; 

if ($n1>$n2) $big = $n1; 

else 

$big = $n2; 

if ($n3>$big)

 $big = $n3; 

echo “Biggest Number is ”.$big; 

?>

 10. (a) What are the differences between echo and print statements? 

     Ans.  Both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.
 
      (b) What is the difference between PHP and JavaScript?

                    Javascript                                                                                  php
Does job for Both Front-end and Back-end.Php is used mostly for Back-end Purposes only.
Javascript is asynchronous, It doesn’t wait for Input Output operations.Php is synchronous, It waits for IO operations to execute.
Can be run in browsers and after Node, we can also run it in Command line3.Php requires a Server to Run. Cannot run without a server.
Js can be combined with HTMl, AJAX and XML.Can be combined with HTML only.
It is a single threaded language that is event-driven which means it never blocks and everything runs concurrently.It is multi-threaded which means it blocks I/O to carry out multiple tasks concurrently.