Beispiel #1
0
 /**
  * Executes an SQL Query and fetches the first two columns only.
  * Then this function builds an associative array using the first
  * column for the keys and the second result column for the
  * values. For instance: SELECT id, name FROM... will produce
  * an array like: id => name.
  * This function allows you to provide an array with values to bind
  * to query parameters. For instance you can bind values to question
  * marks in the query. Each value in the array corresponds to the
  * question mark in the query that matches the position of the value in the
  * array. You can also bind values using explicit keys, for instance
  * array(":key"=>123) will bind the integer 123 to the key :key in the
  * SQL.
  *
  * @param  string $sql		SQL code to execute
  * @param  array  $values	assoc. array binding values
  *
  * @return array  $result	multi dimensional assoc. array result set
  */
 public function getAssoc($sql, $aValues = array())
 {
     $this->sql = $sql;
     $this->signal("sql_exec", $this);
     $rows = $this->db->GetAll($sql, $aValues);
     $assoc = array();
     if ($rows) {
         foreach ($rows as $row) {
             if (count($row) > 0) {
                 $key = array_shift($row);
             }
             if (count($row) > 0) {
                 $value = array_shift($row);
             } else {
                 $value = $key;
             }
             $assoc[$key] = $value;
         }
     }
     return $assoc;
 }
 /**
  * @see RedBean_Adapter::getAssoc
  */
 public function getAssoc($sql, $bindings = array())
 {
     $this->sql = $sql;
     $this->signal('sql_exec', $this);
     $rows = $this->db->GetAll($sql, $bindings);
     $assoc = array();
     if (!$rows) {
         return $assoc;
     }
     foreach ($rows as $row) {
         if (empty($row)) {
             continue;
         }
         if (count($row) > 1) {
             $key = array_shift($row);
             $value = array_shift($row);
         } else {
             $key = array_shift($row);
             $value = $key;
         }
         $assoc[$key] = $value;
     }
     return $assoc;
 }
Beispiel #3
0
 /**
  * Executes an SQL Query and fetches the first two columns only.
  * Then this function builds an associative array using the first
  * column for the keys and the second result column for the
  * values. For instance: SELECT id, name FROM... will produce
  * an array like: id => name.
  * This function allows you to provide an array with values to bind
  * to query parameters. For instance you can bind values to question
  * marks in the query. Each value in the array corresponds to the
  * question mark in the query that matches the position of the value in the
  * array. You can also bind values using explicit keys, for instance
  * array(":key"=>123) will bind the integer 123 to the key :key in the
  * SQL.
  *
  * @param  string $sql		SQL code to execute
  * @param  array  $values	assoc. array binding values
  *
  * @return array  $result	multi dimensional assoc. array result set
  */
 public function getAssoc($sql, $aValues = array())
 {
     $this->sql = $sql;
     $this->signal('sql_exec', $this);
     $timer = new $this->performanceTimerClass(PerformanceTimer::CATEGORY_SQL);
     $timer->startTimer();
     $rows = $this->db->GetAll($sql, $aValues);
     $timer->stopTimer();
     $timer->saveTime();
     $assoc = array();
     if ($rows) {
         foreach ($rows as $row) {
             if (count($row) > 0) {
                 if (count($row) > 1) {
                     $key = array_shift($row);
                     $value = array_shift($row);
                 } elseif (count($row) == 1) {
                     $key = array_shift($row);
                     $value = $key;
                 }
                 $assoc[$key] = $value;
             }
         }
     }
     return $assoc;
 }