From 32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b Mon Sep 17 00:00:00 2001 From: Steve Dibb Date: Thu, 11 Feb 2010 20:17:46 -0700 Subject: initial commit --- class.db.package_use.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 class.db.package_use.php (limited to 'class.db.package_use.php') diff --git a/class.db.package_use.php b/class.db.package_use.php new file mode 100644 index 0000000..4aef84e --- /dev/null +++ b/class.db.package_use.php @@ -0,0 +1,71 @@ +name = $name; + + // Find out as much as we can +// $sql = "SELECT pu.* FROM package_use pu INNER JOIN use u ON pu.use = u.id WHERE u.name = ".$db->quote($name).";"; + $sql = "SELECT * FROM package_use WHERE package = ".$db->quote($package)." AND use = ".$db->quote($use).";"; + $row = $db->getRow($sql); + + if(is_array($row) && count($row)) { + foreach($row as $key => $value) + $this->$key = $value; + } else { + $this->package = $package; + $this->use = $use; + $this->createNew(); + } + + } + + public function __get($var) { + return $this->$var; + } + + public function __set($var, $value) { + + $db =& MDB2::singleton(); + + if(in_array($var, array('package', 'use', 'description'))) { + + $arr_update = array( + $var => $value, + ); + + $db->autoExecute('package_use', $arr_update, MDB2_AUTOQUERY_UPDATE, "id = ".$db->quote($this->id)); + + $this->$var = $value; + + } + + } + + private function createNew() { + + $db =& MDB2::singleton(); + + $arr_insert = array( + 'package' => $this->package, + 'use' => $this->use, + ); + + $db->autoExecute('package_use', $arr_insert, MDB2_AUTOQUERY_INSERT); + + $this->id = $db->lastInsertID(); + + } + + } + +?> \ No newline at end of file -- cgit v1.2.3-65-gdbad