From 2cdf3d0614b1022376e9dae4c1805386bdaf9e85 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 16 Oct 2005 23:41:27 +0000 Subject: [PATCH] Added insert() and delete() actions --- api.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/api.php b/api.php index 7b1254b..359170b 100644 --- a/api.php +++ b/api.php @@ -155,6 +155,12 @@ class API */ var $objdata = array(); + /** + * Insert ID from the insert() command + * @var integer + */ + var $insertid = 0; + /** * Constructor: cannot instantiate class directly */ @@ -296,6 +302,27 @@ class API $this->objdata = $result; } + /** + * Inserts a record in the database + */ + function insert() + { + $this->verify(); + + $actmethod = (method_exists($this, 'pre_insert') ? $this->pre_insert() : ''); + + foreach ($this->setfields AS $field) + { + $fields[] = $field; + $values[] (($this->fields["$field"][0] == TYPE_NOCLEAN OR $this->fields["$field"][0] == TYPE_STR) ? "'" . $this->values["$field"] . "'" : $this->values["$field"]); + } + + $this->registry->modules['db_mysql']->query("INSERT INTO {$this->prefix}{$this->table} (" . implode(',', $fields) . ") VALUES (" . implode(',', $values) . ")"); + $this->insertid = $this->registry->modules['db_mysql']->insert_id(); + + $actmethod = (method_exists($this, 'post_insert') ? $this->post_insert() : ''); + } + /** * Updates a record in the database using the data in $vaues */ @@ -322,6 +349,25 @@ class API $actmethod = (method_exists($this, 'post_update') ? $this->post_update() : ''); } + /** + * Deletes a record + */ + function delete() + { + if ($this->condition == '') + { + trigger_error('Condition is empty: cannot fetch', E_USER_ERROR); + } + + $this->set_existing(); + + $actmethod = (method_exists($this, 'pre_delete') ? $this->pre_delete() : ''); + + $this->registry->modules['db_mysql']->query("DELETE FROM {$this->prefix}{$this->table} WHERE {$this->condition}"); + + $actmethod = (method_exists($this, 'post_delete') ? $this->post_delete() : ''); + } + /** * Verifies that all required fields are set */ -- 2.43.5