BeBot - An Anarchy Online and Age Of Conan chat automaton

General => Feedback and Suggestions => Topic started by: Blueeagle on February 05, 2007, 05:40:36 pm

Title: MySQL should have an option to return associative indexes and not just numeric
Post by: Blueeagle on February 05, 2007, 05:40:36 pm
I am coding a module for bebot but I am annoyed by $this->bot->db->select only returning numeric indexes.

The fix I suggest is simple. The code as it stands now in MySQL.php (version 0.2.1) is:
Quote
function select ($sql)
{
   $data = "";
   $result = mysql_query($sql, $this->CONN);

   if (!$result)
   {
      $this -> error($sql);
      return false;
   }

   if (empty($result))
   {
      return false;
   }

   $count = 0;

   while ($row = mysql_fetch_array($result, MYSQL_NUM))
   {
      $data[$count] = $row;
      $count++;
   }

   mysql_free_result($result);
   return $data;
}

The change that I suggest would look something like:
Quote
function select ($sql, $result_form=MYSQL_NUM)
{
   $data = "";
   $result = mysql_query($sql, $this->CONN);

   if (!$result)
   {
      $this -> error($sql);
      return false;
   }

   if (empty($result))
   {
      return false;
   }

   while ($row = mysql_fetch_array($result, $result_form))
   {
      $data[] = $row;
   }

   mysql_free_result($result);
   return $data;
}

The default is set to MYSQL_NUM and the argument is optional as to not break modules already written.


Thank you for concidering this suggestion.

Edit: There was a way. :)

Terje Monsen
Blueeagl3 on RK1
Title: Re: MySQL should have an option to return associative indexes and not just numer
Post by: Khalem on February 06, 2007, 06:24:49 pm
Submitted to SVN trunk :)
SimplePortal 2.3.7 © 2008-2024, SimplePortal