I found a few entries that dealt directly with my problem but there were no solutions. I am hoping that somebody can provide me with an answer or a link to one. I've been searching all day.

Here is a snippet:

$a->start();

if ($a->checkAuth()) {
    $res =& $mdb2->query('SELECT * FROM perm WHERE username = '.$a->getUsername().'');
    $auth = $res->fetchRow();

if (PEAR::isError($res)) {
    die($res->getMessage());
}
} else {
    $auth['level'] = 'guest';
}

Desired end result is an array $auth['username'], $auth['level'] and so on for just the user selected in the database.

Now, I can get this to work by doing:

$a->start();

if ($a->checkAuth()) {
    $res =& $mdb2->query('SELECT * FROM perm');
    while ($row = $res->fetchRow()) {
        if ($row['username'] == $a->getUsername()) {
            $auth = $row;
        }
    }
    if (PEAR::isError($res)) {
        die($res->getMessage());
    }
} else {
    $auth['level'] = 'guest';
}

... but I'm sure we can see the problem here, very inefficient if the table gets big to take an array of every row and column just to get the one. When I run the top version with no while and a 'WHERE' clause I get this error.

Fatal error: Call to undefined method MDB2_Error::fetchRow() in /home/kansasre/public_html/assets/integral.php on line 77

Why? I'm guessing it has something to do with the result pointer, but I don't care. I just need a way to query one row and get that row's data in an associative array.

Please help.

    Untested, but it should work:

    $a->start();
    
    if ($a->checkAuth()) {
        $sql = "Select username from perm where username = '$username'";
        $res = $mdb2->query($sql);
        if($row = $res->fetchRow()) {
                $auth[''something'] = $row['username'];
        }
        if (PEAR::isError($res)) {
            die($res->getMessage());
        }
    } else {
        $auth['level'] = 'guest';
    } 

      Thank you for your reply. That may very well work, but just before reading this I had found my answer, finally. Here is the snippet I ended up using. It works perfectly.

      $a->start();
      
      if ($a->checkAuth()) {
          $res = $mdb2->queryRow('SELECT * FROM perm WHERE username = \''.$a->getUsername().'\'');
          if (PEAR::isError($res)) {
              die($res->getMessage());
          }
          $auth = $res;
      } else {
          $auth['level'] = 'guest';
      }
      
        Write a Reply...