Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of dave gebler  >  AR DB Interface  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: AR DB Interface
Manage table records as objects using ActiveRecord
Author: By
Last change: added loop load example
Date: 4 years ago
Size: 899 bytes
 

Contents

Class file image Download
<html>

<head>
  <title></title>
</head>

<body>

<?php

require_once('db.php');
require_once(
'mysql.php');
require_once(
'dbi.php');

$db = new MYSQL_DB($db_host,$db_user,$db_pass,$db_name);
$db->connect(); 
$mytable = new ARDBInterface($db,'table_name','id_field');

$mytable->set_id(1);
$mytable->load();
echo 
$mytable->field_name;

$mytable->set_id('');
$mytable->set_field(DBI_ALL_NULL); //These 2 lines clear all fields
$mytable->some_field '1';
while (
$mytable->load()) // or e.g. load(array('order' => 'field_name DESC'))
{
   
// do whatever
}

$mytable->field_name $value;
$mytable->update();

$mytable->import_fields($_POST); // $_POST['field_name'] would map to object and the class takes care of escaping DB queries before execution
$mytable->update();

$myarray $mytable->fields_array();
echo 
$myarray['field_name'];

?>

</body>

</html>