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

Product PHP

The PHP class defines a Product model with properties like pin, validity, and mac that correspond to columns in a database table. The class constructor accepts a database connection. Methods like readOne() and update() prepare and execute queries to select and update a single product record matching the pin property. The readOne() method retrieves a row and maps the column values to object properties, while update() binds new property values to a prepared update statement.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Product PHP

The PHP class defines a Product model with properties like pin, validity, and mac that correspond to columns in a database table. The class constructor accepts a database connection. Methods like readOne() and update() prepare and execute queries to select and update a single product record matching the pin property. The readOne() method retrieves a row and maps the column values to object properties, while update() binds new property values to a prepared update statement.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<?

php
class Product{

// database connection and table name


private $conn;
private $table_name = "rotus";

// object properties
public $pin;
public $validity;
public $fstlgtim;
public $exptim;
public $mac;
public $vu;
public $vp;
public $sts;

// constructor with $db as database connection


public function __construct($db){
$this->conn = $db;
}

//_______________________read one_____________________________
// used when filling up the update product form
function readOne(){

// query to read single record


$query = "SELECT * FROM " . $this->table_name . " WHERE pin = ?";

// prepare query statement


$stmt = $this->conn->prepare( $query );

// bind id of product to be updated


$stmt->bindParam(1, $this->pin);

// execute query
$stmt->execute();

// get retrieved row


$row = $stmt->fetch(PDO::FETCH_ASSOC);

// set values to object properties


$this->pin = $row['pin'];
$this->validity = $row['validity'];
$this->fstlgtim = $row['fstlgtim'];
$this->exptim = $row['exptim'];
$this->mac = $row['mac'];
$this->vu = $row['vu'];
$this->vp = $row['vp'];
$this->sts = $row['sts'];
}

function update()
{
$query2 = "UPDATE " . $this->table_name . " SET
fstlgtim = :fstlgtim,
exptim = :exptim,
mac = :mac
WHERE
pin = :pin";
// prepare query statement
$stmt = $this->conn->prepare( $query2 );

/*bind upate field


$stmt->bindParam(1, $this->fstlgtim);
$stmt->bindParam(2, $this->exptim);
$stmt->bindParam(3, $this->mac);
$stmt->bindParam(4, $this->pin);
*/
// sanitize
$this->fstlgtim=htmlspecialchars(strip_tags($this->fstlgtim));
$this->exptim=htmlspecialchars(strip_tags($this->exptim));
$this->mac=htmlspecialchars(strip_tags($this->mac));

// bind new values


$stmt->bindParam(':fstlgtim', $this->fstlgtim, PDO::PARAM_STR);
$stmt->bindParam(':exptim', $this->exptim, PDO::PARAM_STR);
$stmt->bindParam(':mac', $this->mac, PDO::PARAM_STR);
$stmt->bindParam(':pin', $this->pin, PDO::PARAM_INT);

// execute the query


$stmt->execute();
}

//--------------New Update Codes


Start-------------------------------------------------------
function updatelstuse()
{
$query3 = "UPDATE " . $this->table_name . " SET
lstuse = Now()
WHERE
pin = :pin";
// prepare query statement
$stmt = $this->conn->prepare( $query3 );

/*bind upate field


$stmt->bindParam(1, $this->fstlgtim);
$stmt->bindParam(2, $this->exptim);
$stmt->bindParam(3, $this->mac);
$stmt->bindParam(4, $this->pin);
*/
// sanitize
// $this->fstlgtim=htmlspecialchars(strip_tags($this->fstlgtim));
// $this->exptim=htmlspecialchars(strip_tags($this->exptim));
// $this->mac=htmlspecialchars(strip_tags($this->mac));

// bind new values


// $stmt->bindParam(':fstlgtim', $this->fstlgtim, PDO::PARAM_STR);
// $stmt->bindParam(':exptim', $this->exptim, PDO::PARAM_STR);
// $stmt->bindParam(':mac', $this->mac, PDO::PARAM_STR);
$stmt->bindParam(':pin', $this->pin, PDO::PARAM_INT);

// execute the query


$stmt->execute();
}
//-----------New Update Code END
----------------------------------------------------

}
?>

You might also like