+ /**
+ * Insert an array of data into a table
+ * @param string $table WARNING: not sanitized!
+ * @param array $data should not already be SQL-escaped
+ * @return mixed results of $this->query()
+ */
+ function insert($table, $data) {
+ $data = add_magic_quotes($data);
+ $fields = array_keys($data);
+ return $this->query("INSERT INTO $table (`" . implode('`,`',$fields) . "`) VALUES ('".implode("','",$data)."')");
+ }
+
+ /**
+ * Update a row in the table with an array of data
+ * @param string $table WARNING: not sanitized!
+ * @param array $data should not already be SQL-escaped
+ * @param array $where a named array of WHERE column => value relationships. Multiple member pairs will be joined with ANDs. WARNING: the column names are not currently sanitized!
+ * @return mixed results of $this->query()
+ */
+ function update($table, $data, $where){
+ $data = add_magic_quotes($data);
+ $bits = $wheres = array();
+ foreach ( array_keys($data) as $k )
+ $bits[] = "`$k` = '$data[$k]'";
+
+ if ( is_array( $where ) )
+ foreach ( $where as $c => $v )
+ $wheres[] = "$c = '" . $this->escape( $v ) . "'";
+ else
+ return false;
+ return $this->query( "UPDATE $table SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres ) . ' LIMIT 1' );
+ }