From: Domas Mituzas Date: Thu, 19 Aug 2004 13:02:01 +0000 (+0000) Subject: allow getField, selectField and select to have empty conditions and table names. X-Git-Tag: 1.5.0alpha1~2292 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=31e4c31bd443b54f34ae112bc6225864e42dffc2;p=lhc%2Fweb%2Fwiklou.git allow getField, selectField and select to have empty conditions and table names. --- diff --git a/includes/Database.php b/includes/Database.php index 6e78902e30..04b21f66c4 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -326,14 +326,14 @@ class Database { return !!$this->query( $sql, DB_MASTER, $fname ); } - function getField( $table, $var, $cond, $fname = "Database::get", $options = array() ) { + function getField( $table, $var, $cond="", $fname = "Database::get", $options = array() ) { return $this->selectField( $table, $var, $cond, $fname = "Database::get", $options = array() ); } # Simple SELECT wrapper, returns a single field, input must be encoded # Usually aborts on failure # If errors are explicitly ignored, returns FALSE on failure - function selectField( $table, $var, $cond, $fname = "Database::selectField", $options = array() ) + function selectField( $table, $var, $cond="", $fname = "Database::selectField", $options = array() ) { if ( !is_array( $options ) ) { $options = array( $options ); @@ -385,21 +385,25 @@ class Database { } # SELECT wrapper - function select( $table, $vars, $conds, $fname = "Database::select", $options = array() ) + function select( $table, $vars, $conds="", $fname = "Database::select", $options = array() ) { if ( is_array( $vars ) ) { $vars = implode( ",", $vars ); } - $table = $this->tableName( $table ); + if ($table!="") + $from = " FROM " .$this->tableName( $table ); + else + $from = ""; + list( $useIndex, $tailOpts ) = $this->makeSelectOptions( $options ); - if ( $conds !== false ) { + if ( $conds !== false && $conds != "" ) { if ( is_array( $conds ) ) { $conds = $this->makeList( $conds, LIST_AND ); } - $sql = "SELECT $vars FROM $table $useIndex WHERE $conds $tailOpts"; + $sql = "SELECT $vars $from $useIndex WHERE $conds $tailOpts"; } else { - $sql = "SELECT $vars FROM $table $useIndex $tailOpts"; + $sql = "SELECT $vars $from $useIndex $tailOpts"; } return $this->query( $sql, $fname ); }