diff options
-rw-r--r-- | index.php | 7 | ||||
-rw-r--r-- | isis.php | 86 |
2 files changed, 91 insertions, 2 deletions
@@ -177,10 +177,13 @@ include('spyc/spyc.php'); <h3>query reading a record</h3> <?php - $r = $db->read(3); + $r = $db->read(6); echo "<pre>---\n", $r->toString(), "---\n</pre><br>\n"; echo '<pre>'; - echo print_r($r); + //print_r($r); + //print_r($r->val[8]); + print_r(preg_split('/\t/', $r->val[7])); + echo '</pre>'; } // end else could contact server ?> diff --git a/isis.php b/isis.php new file mode 100644 index 0000000..66b3b7d --- /dev/null +++ b/isis.php @@ -0,0 +1,86 @@ +<?php +/** + * Database procedures. + */ + +/** + * Schema format example. + */ +$schema = array( + 'db' => array( + 'name' => 'dbname', + ), + 'fields' => array( + 'field_name' => array( + 'id' => 1, + 'size' => 1000, + 'format' => 'numeric', + 'repeat' => TRUE, + 'subfields' => array( + 'a' => 'test', + 'b' => 'test2', + ), + ), + ), +); + +/** + * Generic interface for reading Isis databases. + */ +interface IsisDb { + // Constructor. + public function __construct($schema); + + // Return field data for a given entry. + public function fields($id); + + // Return subfield data for a given entry. + public function subfields($id); + + // Read an entry. + public function read($id); + + // Return number of rows in the database. + public function rows(); +} + +/** + * Malete implementation of IsisDb. + */ +class MaleteDb implements IsisDb { + var $fdt; + var $db; + var $format; + + public function __construct($schema) { + // Save db schema. + $format = $schema; + + // Setup $fdt used by malete. + foreach ($schema['fields'] as $field => $info) { + $fdt[$field] = $info['id']; + } + + // Open a database connection. + $db = new Isis_Db($fdt, $schema['db']['name'], new Isis_Server()); + } + + public function fields($id == NULL) { + } + + public function subfields($id == NULL) { + } + + // TODO: put result into $schema format. + public function read($id) { + if (!is_numeric($id) { + return FALSE; + } + return $this->$db->read($id); + } + + public function rows() { + } +} + +?> |