0% found this document useful (0 votes)
11 views3 pages

MSBTE PHP Additional Important Questions

The document outlines key concepts and code examples related to PHP web application development, including differences between include() and require(), object cloning, and validation methods. It provides sample PHP programs for creating PDFs, sorting arrays, managing sessions, and inserting data into a MySQL database. Additionally, it explains the use of specific functions and methods, such as __call() and explode().

Uploaded by

Yogesh Rathod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

MSBTE PHP Additional Important Questions

The document outlines key concepts and code examples related to PHP web application development, including differences between include() and require(), object cloning, and validation methods. It provides sample PHP programs for creating PDFs, sorting arrays, managing sessions, and inserting data into a MySQL database. Additionally, it explains the use of specific functions and methods, such as __call() and explode().

Uploaded by

Yogesh Rathod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Additional Important Questions - Web Based Application Development with PHP (MSBTE)

1. Explain the difference between include() and require() in PHP.

- include(): Emits a warning if the file is not found, script continues.

- require(): Emits a fatal error if the file is not found, script stops.

2. Write a PHP program to create a PDF document.

require('fpdf.php');

$pdf = new FPDF();

$pdf->AddPage();

$pdf->SetFont('Arial','B',16);

$pdf->Cell(40,10,'Hello World!');

$pdf->Output();

3. Explain the use of the __call() magic method in PHP.

Used when an undefined or inaccessible method is called on an object.

Example:

class MyClass {

public function __call($name, $arguments) {

echo "Method $name does not exist.";

4. Differentiate between client-side and server-side validation.

- Client-side: Done in the browser, faster but insecure.

- Server-side: Done on server, secure and reliable.


5. Write a PHP program to sort an array of numbers.

$numbers = array(4, 2, 8, 6);

sort($numbers);

foreach ($numbers as $num) {

echo $num . " ";

6. Explain the concept of cloning an object in PHP.

clone keyword is used to create a shallow copy of an object.

Example:

$obj2 = clone $obj1;

7. Write a PHP program to demonstrate the use of sessions.

session_start();

$_SESSION["username"] = "JohnDoe";

echo $_SESSION["username"];

8. Explain the difference between mysqli_connect() and PDO.

- mysqli_connect(): MySQL-specific, procedural.

- PDO: Object-oriented, supports multiple DBs, more secure.

9. Write a PHP program to insert data into a MySQL database.

$conn = mysqli_connect("localhost", "username", "password", "database");

$sql = "INSERT INTO users (name, email) VALUES ('John', '[email protected]')";

mysqli_query($conn, $sql);

mysqli_close($conn);
10. Explain the use of the explode() function in PHP.

Splits a string into an array.

$str = "apple,banana,cherry";

$array = explode(",", $str);

You might also like