Dynamically Insert and Update Values In a MySQL Database Using OOP - You Wouldn't Have to Update It Had You Gotten It Right the First Time (
Page 7 of 7 )
The blob:
// Include the file that contains
// the MyDatabase class
require('database.class.php');
// If the form was submitted...
if($_POST['id'])
{
// Instantiate the class
$SQL = new MyDatabase;
// Connect to the database
$SQL->Connect();
// Update values in my_tbl
// where id = $_POST['id']
if(!$SQL->UpdateDB('my_tbl',
$_POST['id'], 'id'))
die( $SQL->GetError() );
// Disconnect from the database
$SQL->Disconnect();
}
Look familiar? It should, unless you accidentally / intentionally skipped a section or two. The only difference now is we are using the UpdateDB method to update our table and now we are passing the id and the name of the id column in the database table.
You Are Much Faster Now, Grasshopper
Now you are able to focus, grasshopper. No more annoying insert and update statements to distract you. This class has become a permanent "must have" in my arsenal of includes. It's like an audio stream from Digitally Imported Radio (www.di.fm) - I never code without it.
So there you have it; my 2 dollars. It is my hope that you will find this class as helpful as I have. Just don't use it in a production environment without adding some more validation and better error reporting and so on. Until next time!