<?PHP

require_once('Auth/OpenID/DatabaseConnection.php');

class Auth_OpenId_AxisDatabase extends Auth_OpenId_DatabaseConnection {
    function query($sql, $params=array())
    {
        global $DB;

        return $DB->Query( $this->do_params_insert($sql,$params) );
    }

    function getOne($sql, $params=array())
    {
        global $DB;

        if ($DB->Query( $this->do_params_insert($sql,$params) ) !== FALSE)
        {
            $Row = $DB->FetchRow();
            $rc = array_shift($Row);
            return $rc;
        }
        else
        {
            return FALSE;
        }
    }

    function getRow($sql, $params=array())
    {
        global $DB;

        if ($DB->Query( $this->do_params_insert($sql,$params) ) !== FALSE)
        {
            $Row = $DB->FetchRow();
            return $Row;
        }
        else
        {
            return FALSE;
        }
    }

    function getAll($sql, $params=array())
    {
        global $DB;

        if ($DB->Query( $this->do_params_insert($sql,$params) ) !== FALSE)
        {
            $All = array();
            while ($Row = $DB->FetchRow())
            {
                $All []= $Row;
            }
            return $All;
        }
        else
        {
            return FALSE;
        }
    }

    private function do_params_insert($sql, $params=array())
    {
        $rc ="";
        for ($i=0; $i<strlen($sql); $i++)
        {
            if ($sql[$i] == '?' || $sql[$i] == '!' )
            {
                $data = array_shift($params);

                if (preg_match("/^[0-9]+$/", $data) ||
                    preg_match("/^0x[0-9a-f]+$/", $data) )
                {
                    $rc .= $data;
                }
                else
                {
                    $rc .= "'".addslashes($data)."'";
                }
            }
            else
            {
                $rc .= $sql[$i];
            }
        }

        return $rc;
    }
}

?>