PHP Classes

File: example/update_demo.php

Recommend this page to a friend!
  Classes of Slawomir Kaleta   Dframe Database   example/update_demo.php   Download  
File: example/update_demo.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Dframe Database
Access a MySQL database using PDO
Author: By
Last change: Update of example/update_demo.php
Date: 3 years ago
Size: 1,190 bytes
 

Contents

Class file image Download
<?php

// include pdo helper class to use common methods
require_once '../src/Helper/PDOHelper.php';
// include pdo class wrapper
require_once '../src/class.pdowrapper.php';

// database connection setings
$dbConfig = ['host' => 'localhost', 'dbname' => 'sampledb', 'username' => 'root', 'password' => ''];
// get instance of PDO Wrapper object
$db = new PdoWrapper($dbConfig);

// get instance of PDO Helper object
$helper = new PDOHelper();

// set error log mode true to show error on screen or false to log in log file
$db->setErrorLog(true);

// Example -1

// update array data
$dataArray = ['first_name' => 'Sangeeta', 'last_name' => 'Mishra', 'age' => 35];
// where condition array
$aWhere = ['id' => 23];
// call update function
$q = $p->update('test', $dataArray, $aWhere)->showQuery()->affectedRows();
// print affected rows
PDOHelper::PA($q);

// Example -2

// update array data
$dataArray = ['first_name' => 'Sonia', 'last_name' => 'Shukla', 'age' => 23];
// two where condition array
$aWhere = ['age' => 35, 'last_name' => 'Mishra'];
// call update function
$q = $p->update('test', $dataArray, $aWhere)->showQuery()->affectedRows();
// print affected rows
PDOHelper::PA($q);