PHP Classes

File: sample.php

Recommend this page to a friend!
  Classes of Iván Campaña   Data Objects   sample.php   Download  
File: sample.php
Role: Example script
Content type: text/plain
Description: Sample script to test the functionality
Class: Data Objects
Supply an interface to treat table rows as objects
Author: By
Last change:
Date: 19 years ago
Size: 1,026 bytes
 

Contents

Class file image Download
<?php

/*
Setting fetch mode for ADODB for further information about this read the ADODB documentation
*/
define('ADODB_FETCH_ASSOC',2);
define('ADODB_ASSOC_CASE', 2); # use native-case for ADODB_FETCH_ASSOC
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

include(
"adodb/adodb.inc.php");
include(
"data_objects.php");

$database = &ADONewConnection('mysql');
$database->Connect('localhost', 'root', '', 'catalogo'); # connect to DB

$table = new dataObject($database, "producto"); // Opens the table called producto

$table->load(2); // If the PK is a single field index just send the Id
//$table->load(array("id"=>2, "client_id"=>1)); // If the PK is composed send the multiple fields as an array

$table->set('nombre', "Vino de cocox");
$table->set('cantidad', 6);
$table->set('valor', 14);

// If the product using the selected ID doesn't exists the register is inserted, else is updated
$table->store();

//$table->delete();
print $table->_error; // If there is no error then nothing is printed.

?>