PHP Classes

File: Example.UpdateTableWithArray.php

Recommend this page to a friend!
  Classes of Dustin Ruckman   DB Access using PDO   Example.UpdateTableWithArray.php   Download  
File: Example.UpdateTableWithArray.php
Role: Example script
Content type: text/plain
Description: Update a table using an array of values by a unique id
Class: DB Access using PDO
Query MySQL tables with prepared queries using PDO
Author: By
Last change:
Date: 9 years ago
Size: 587 bytes
 

Contents

Class file image Download
<?php

require('path/to/DatabaseAccess.Class.php');

$DbAccess = new DatabaseAccess("yourHost", "dbName", "dbUser", "dbUserPassword");

// The array containing the values to use. This could be a cleaned up POST from a form
$arrayOfValues = array(
   
'ID' => 1000, // Make sure you include the value of the UniqueID
   
'FirstName' => 'Bob',
   
'LastName' => 'Moore',
   
'City' => 'Somewhere',
   
'State' => 'SomeState',
   
'Password' => 'DontUsePlainText'
);

// Just call this and Done
$numberOfRowsUpdated = $DbAccess->UpdateTableViaArrayByID("UserAccounts", "ID", $arrayOfValues);