SwatDB/SwatDB.php
public static function queryOneFromTable(
        $db,
        $table,
        $field,
        $id_field = null,
        $id = 0
    ) {
        $field = new SwatDBField($field, 'integer');

        if ($id_field == null) {
            $sql = 'select %s from %s';
            $sql = sprintf($sql, $field->name, $table);
        } else {
            $id_field = new SwatDBField($id_field, 'integer');
            $sql = 'select %s from %s where %s = %s';
            $sql = sprintf(
                $sql,
                $field->name,
                $table,
                $id_field->name,
                $db->quote($id, $id_field->type)
            );
        }

        $value = self::queryOne($db, $sql, $field->type);

        return $value;
    }
public static function queryOneFromTable(
        $db,
        $table,
        $field,
        $id_field = null,
        $id = 0
    ) {
        $field = new SwatDBField($field, 'integer');

        if ($id_field == null) {
            $sql = 'select %s from %s';
            $sql = sprintf($sql, $field->name, $table);
        } else {
            $id_field = new SwatDBField($id_field, 'integer');
            $sql = 'select %s from %s where %s = %s';
            $sql = sprintf(
                $sql,
                $field->name,
                $table,
                $id_field->name,
                $db->quote($id, $id_field->type)
            );
        }

        $value = self::queryOne($db, $sql, $field->type);

        return $value;
    }
public static function queryOneFromTable ( $ db , $ table , $ field , $ id_field = null , $ id = 0 ) { $ field = new SwatDBField ( $ field , 'integer' ) ; if ( $ id_field == null ) { $ sql = 'select %s from %s' ; $ sql = sprintf ( $ sql , $ field -> name , $ table ) ; } else { $ id_field = new SwatDBField ( $ id_field , 'integer' ) ; $ sql = 'select %s from %s where %s = %s' ; $ sql = sprintf ( $ sql , $ field -> name , $ table , $ id_field -> name , $ db -> quote ( $ id , $ id_field -> type ) ) ; } $ value = self :: queryOne ( $ db , $ sql , $ field -> type ) ; return $ value ; }
Query a single value from a specified table and column

Convenience method to query a single value in a single database column.

@param MDB2_Driver_Common $db The database connection.

@param string $table The database table to query.

@param string $field The name of the database field to query. Can be
given in the form type:name where type is a standard MDB2
datatype. If type is ommitted, then integer is assummed for this
field.

@param string $id_field The name of the database field that contains the
the id.  If not null this will be used to construct a where clause
to limit results. Can be given in the form type:name where type is
a standard MDB2 datatype. If type is ommitted, then integer is
assummed for this field.

@param mixed $id The value to look for in the $id_field. The type should
correspond to the type of $id_field.

@return mixed The value queried for a single result.

@throws SwatDBException
Query a single value from a specified table and column