0% found this document useful (0 votes)
11 views

Constructor and Destructor Coding

This document contains code examples demonstrating the use of constructors and destructors in PHP. It creates a Demo class with a constructor and destructor method, then instantiates a Demo object both inside and outside of a function to show the constructor and destructor being called at the appropriate times. It also outputs the various steps.

Uploaded by

Selva Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Constructor and Destructor Coding

This document contains code examples demonstrating the use of constructors and destructors in PHP. It creates a Demo class with a constructor and destructor method, then instantiates a Demo object both inside and outside of a function to show the constructor and destructor being called at the appropriate times. It also outputs the various steps.

Uploaded by

Selva Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CONSTRUCTOR AND DESTRUCTOR CODING: <!

doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Constructors and Destructors</title> <link rel="stylesheet" href="style.css"> </head> <body> <?php # Script 4.7 - demo.php class Demo { function _ _construct() { echo '<p>In the constructor.</p>'; } function _ _destruct() { echo '<p>In the destructor.</p>'; } } function test() { echo '<p>In the function. Creating a new object...</p>'; $f = new Demo(); echo '<p>About to leave the function.</p>'; } echo '<p>Creating a new object...</p>';

$o = new Demo(); echo '<p>Calling the function...</p>'; test(); echo '<p>About to delete the object...</p>'; unset($o); echo '<p>End of the script.</p>'; ?> </body> </html> OUTPUT:

DDL COMMANDS CODING:

<?php $mysqli = new mysqli("localhost", "my_user", "my_password ", "world"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error() ); exit(); } $city = "Amersfoort"; $stmt = $mysqli->stmt_init(); if ($stmt>prepare("SELECT District FROM City WHERE Name=?")) { $stmt->bind_param("s", $city); $stmt->execute(); $stmt->bind_result($district); $stmt->fetch(); printf("%s is in district %s\n", $city, $district); $stmt->close(); } $mysqli->close(); ?> 2)DDL COMMANDS Coding: <?php $conn = db2_connect($database, $user, $password); $create = 'CREATE TABLE animals (id INTEGER, breed VARCHA

R(32),name CHAR(16), weight DECIMAL(7,2))'; $result = db2_exec($conn, $create); if ($result) { print "Successfully created the table.\n"; } $animals = array( array(0, 'cat', 'Pook', 3.2), array(1, 'dog', 'Peaches', 12.3), array(2, 'horse', 'Smarty', 350.0), array(3, 'gold fish', 'Bubbles', 0.1), array(4, 'budgerigar', 'Gizmo', 0.2), array(5, 'goat', 'Rickety Ride', 9.7), array(6, 'llama', 'Sweater', 150) ); foreach ($animals as $animal) { $rc = db2_exec($conn, "INSERT INTO animals (id, breed , name, weight) VALUES ({$animal[0]}, '{$animal[1]}', '{$animal[2]} ', {$animal[3]})"); if ($rc) { print "Insert... "; } } ?>

output:
Successfully created the table. Insert... Insert... Insert... Insert... Insert... Insert... Insert...

3) coding:
<?php $conn = db2_connect($database, $user, $password); $sql = "SELECT name FROM animals WHERE weight < 10.0 ORDER BY name"; if ($conn) { require_once('prepare.inc'); $stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLL ABLE)); while ($row = db2_fetch_array($stmt)) { print "$row[0]\n"; } } ?>

output:
Bubbles Gizmo Pook Rickety Ride

You might also like