From: konrad Date: Sat, 4 Aug 2007 16:39:10 +0000 (+0000) Subject: fix some typos X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=772380a3577a2d85e56c97c143801603696e01e6;p=web%2Fkonrad%2Fsmoke.git fix some typos add setConfig to $db add update() to $db git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@17 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/www/inc/db.php b/www/inc/db.php index adad151..00b4495 100644 --- a/www/inc/db.php +++ b/www/inc/db.php @@ -56,6 +56,9 @@ abstract class DbEngine /**insert values into a table*/ public abstract function insert($table,array $values); + /**update database values*/ + public abstract function update($table,array $values,$where); + /**creates a table; the argument is an array of the form "col-name" => array("col-type", "flags"...); use sqlCreateTable() etc. to create the actual statement*/ protected abstract function createTable($tablename,$table); @@ -150,6 +153,31 @@ abstract class DbEngine return $ret; } + /**creates a SQL92 statement for updates*/ + protected function sqlUpdate($table,array $values,$where) + { + global $dbScheme; + $ret="UPDATE ".$this->tableName($table)." SET "; + reset($values); + $cm=""; + while(list($k,$v)=each($values)){ + $ret.=$cm;$cm=","; + //append column name + $ret.=$k."="; + //append value + if($dbScheme->isIntColumn($table,$k)) + $val.=$this->escapeInt($v); + else + if($dbScheme->isStringColumn($table,$k)) + $val.=$this->escapeString($v); + else + //don't know how to escape it... + $val.="NULL"; + } + $ret.=" WHERE ".$where; + return $ret; + } + /**escapes integers; the default implementation just makes sure it is an int*/ protected function escapeInt($i) { @@ -170,6 +198,16 @@ abstract class DbEngine return false; } + /**sets a config setting*/ + public function setConfig($key,$val) + { + $this->beginTransaction(); + $mar=$this->select("config","cval","ckey='".addslashes($key)."'"); + if(count($mar)>0)$this->update("config",array("cval"=>$val),"ckey='".addslashes($key)."'"); + else $this->insert("config",array("ckey"=>$key,"cval"=>$val)); + $this->commitTransaction(); + } + /**tries to find out whether the connected DB version is usable*/ public function canUseDb() { diff --git a/www/inc/db_mysql.php b/www/inc/db_mysql.php index 0032133..1ed42f4 100644 --- a/www/inc/db_mysql.php +++ b/www/inc/db_mysql.php @@ -120,6 +120,11 @@ class MysqlEngine extends DbEngine return mysql_query($this->sqlInsert($table,$values)); } + public function update($table,array $values,$where) + { + mysql_query($this->sqlUpdate($table,$values,$where)); + } + public function lastError() { return mysql_error(); diff --git a/www/inc/listing.php b/www/inc/listing.php index c51fdb3..108e9e0 100644 --- a/www/inc/listing.php +++ b/www/inc/listing.php @@ -7,7 +7,7 @@ function createlist() $p=new Parser("index.html"); $p->setVar("ROLE","buyer"); $list=""; - $temp=$p->getVar("EVENT");; + $temp=$p->getVar("EVENT"); //fake1 $p->setVars(array("DATE"=>"heute","PLACE"=>"nirgendwo","EVENTNAME"=>"Hurrah Jazz Club","ARTIST"=>"Broken Blech","PRICE"=>"567,00","ID"=>"1")); $list.=$p->parse($temp); diff --git a/www/index.php b/www/index.php index 7c0a0d9..e8b71e1 100644 --- a/www/index.php +++ b/www/index.php @@ -8,8 +8,8 @@ include('inc/parser.php'); //set common basics $mode="index"; -if(isset($_GET[mode])){ - $mode=$_GET[mode]; +if(isset($_GET["mode"])){ + $mode=$_GET["mode"]; } $parser=new Parser();