PHP Classes

File: asimple_demo.php

Recommend this page to a friend!
  Classes of Matt Saragusa   A Simple MySQL Class   asimple_demo.php   Download  
File: asimple_demo.php
Role: Example script
Content type: text/plain
Description: An example file
Class: A Simple MySQL Class
Execute MySQL queries from argument values
Author: By
Last change:
Date: 15 years ago
Size: 1,974 bytes
 

Contents

Class file image Download
<?php
// You have to include the class file asimple.php
require_once('asimple.php');

// Create the dataset
$dataset = new ASimpleMySQLDB(SIMPLE_DB_SERVER, SIMPLE_DB_NAME, SIMPLE_DB_USERNAME, SIMPLE_DB_PASSWORD);


// Populating a database

$inserts[] = array('name' => '1GB Jump Drive','description' => 'One Gigabyte USB Jump Drive','catID' => 1);
$inserts[] = array('name' => '2GB Jump Drive','description' => 'Two Gigabyte USB Jump Drive','catID' => 1);
$inserts[] = array('name' => '5GB Jump Drive','description' => 'Five Gigabyte USB Jump Drive','catID' => 1);
$inserts[] = array('name' => 'Wireless g Router','description' => 'Short Range Wireless Router','catID' => 2);
$inserts[] = array('name' => 'Wireless n Router','description' => 'Long Range Wireless Router','catID' => 2);

foreach(
$inserts as $insert) {

   
$dataset->insert_array('Items', $insert);
}

// =========================================================================

// Updating a recordset
$update = array('name' => 'Wireless N Router','description' => 'Super Long Range Wireless Router','catID' => 2);

$dataset->update_array('Items', 'itemID', 5, $update);

// =========================================================================
echo '<pre>';
// Selecting a row from the database
$myItem = $dataset->get_record_by_ID('Items', 'itemID', 1);
echo
$myItem['name']."\n";
echo
$myItem['description']."\n";
echo
"*********************************************\n";

// =========================================================================

// Selecting a group from the database
// Here you would be selecting all records in the wireless router category
$myItems = $dataset->get_records_by_group('Items', 'catID', 2);

foreach(
$myItems as $myItem) {
    echo
$myItem['name']."\n";
    echo
$myItem['description']."\n";
    echo
"=============================================\n";
}
echo
"*********************************************\n";

?>