cvs: pearweb /include pear-database.php

From: Date: Thu, 30 Aug 2001 13:47:30 +0000
Subject: cvs: pearweb /include pear-database.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-699@lists.php.net to get a copy of this message
cox Thu Aug 30 09:47:30 2001 EDT Modified files: /pearweb/include pear-database.php Log: added add_category() (add_package() is no longer right so comment it out) Index: pearweb/include/pear-database.php diff -u pearweb/include/pear-database.php:1.9 pearweb/include/pear-database.php:1.10 --- pearweb/include/pear-database.php:1.9 Mon Aug 20 22:06:44 2001 +++ pearweb/include/pear-database.php Thu Aug 30 09:47:29 2001 @@ -72,7 +72,7 @@ function renumber_visitations($debug = false) { global $dbh; - $sth = $dbh->query("SELECT * FROM packages ORDER BY name"); + $sth = $dbh->query("SELECT * FROM categories ORDER BY name"); if (DB::isError($sth)) { return $sth; } @@ -105,7 +105,7 @@ if ($debug) { print "updating $node\n"; } - $query = "UPDATE packages SET leftvisit = $l, rightvisit = $r ". + $query = "UPDATE categories SET leftvisit = $l, rightvisit = $r ". "WHERE name = '$node'"; $dbh->query($query); } @@ -113,9 +113,40 @@ } // }}} +/* +$data = array( + 'name' => 'category name', + 'desc' => 'category description', + 'parent' => 'category parent id' + ); +*/ +function add_category($data) +{ + global $dbh; + $name = $data['name']; + if (empty($name)) { + return PEAR::raiseError('no name given'); + } + $desc = (empty($data['desc'])) ? 'none' : $data['desc']; + $parent = (empty($data['parent'])) ? null : $data['parent']; + + $sql = 'INSERT INTO categories (id, name, description, parent)'. + 'VALUES (?, ?, ?, ?)'; + $id = $dbh->nextId('categories'); + $sth = $dbh->prepare($sql); + if (DB::isError($sth)) { + return $sth; + } + $err = $dbh->execute($sth, array($id, $name, $desc, $parent)); + if (DB::isError($err)) { + return $err; + } + return renumber_visitations(); +} + // {{{ add_package() -function add_package($data) +/*function add_package($data) { global $dbh; $defaults = array( @@ -143,7 +174,7 @@ return $err; } return renumber_visitations(); -} +}*/ // }}}

« previous php.pear.cvs (#699) next »