Query database table
@param string $query SQL statement.
@param bool retarray default false. If true then returns an array with result, num_rows
@return mixed result-set for select etc, true/false for insert etc.
On error calls SqlError() and exits.
195105
public function query($query, $retarray=false) {
    $db = $this->opendb();

    $result = mysql_query($query, $db);

    if(!$result) {
      //echo "error=" . mysql_error($db) . "<br>error code=" . mysql_errno($db) . "<br>";
      throw new SqlException($query, $this);
    }

    $this->result = $result;
    
    if($retarray) {
      if(!preg_match("/^(?:select|show)/i", $query)) {
        //echo "NOT SELECT<br>";
        $numrows = mysql_affected_rows($db);
      } else {
        //echo "SELECT: query=$query, result=$result<br>";
        $numrows = mysql_num_rows($result);
      }
      return array($result, $numrows, result=>$result, numrows=>$numrows);
    } else {
      return $result;
    }
  }
502401
public function query($query)
    {
        // If the query is empty, we'll return false
        if ($query === null || empty($query)) {
            return false;
        }

        if ($this->read) {
            // If read is true, we'll perform a read search, retrieving one record
            $results = $this->connection->read($this->getDn(), $query, $this->getSelects());
        } elseif ($this->recursive) {
            // If recursive is true, we'll perform a recursive search
            $results = $this->connection->search($this->getDn(), $query, $this->getSelects());
        } else {
            // Read and recursive is false, we'll return a listing
            $results = $this->connection->listing($this->getDn(), $query, $this->getSelects());
        }

        if ($results) {
            return $this->processResults($results);
        }

        return false;
    }
1372688
public function query( $query ) {
		if ( ! $this->ready ) {
			if ( isset( $this->check_current_query ) ) {
				// This property was introduced in WP 4.2
				$this->check_current_query = true;
			}
			return false;
		}

		if ( $this->show_errors ) {
			$this->hide_errors();
		}

		$result = parent::query( $query );

		if ( ! SAVEQUERIES ) {
			return $result;
		}

		$i = $this->num_queries - 1;
		$this->queries[ $i ]['trace'] = new QM_Backtrace( array(
			'ignore_frames' => 1,
		) );

		if ( ! isset( $this->queries[ $i ][3] ) ) {
			$this->queries[ $i ][3] = $this->time_start;
		}

		if ( $this->last_error ) {
			$code = 'qmdb';
			if ( $this->use_mysqli ) {
				if ( $this->dbh instanceof mysqli ) {
					$code = mysqli_errno( $this->dbh );
				}
			} else {
				if ( is_resource( $this->dbh ) ) {
					// Please do not report this code as a PHP 7 incompatibility. Observe the surrounding logic.
					// @codingStandardsIgnoreLine
					$code = mysql_errno( $this->dbh );
				}
			}
			$this->queries[ $i ]['result'] = new WP_Error( $code, $this->last_error );
		} else {
			$this->queries[ $i ]['result'] = $result;
		}

		return $result;
	}
646436
private static function parseQuery( $query )
   {

      if ( empty( $query ) )
      {
         return [];
      }

      $elements = [];

      \parse_str( $query, $elements );

      if ( ! \is_array( $elements ) )
      {
         return [];
      }

      return $elements;

   }
1287541
public function query($sql,$parse=false) {
        if(!is_bool($parse) && !is_array($parse)) {
            $parse = func_get_args();
            array_shift($parse);
        }
        $sql  =   $this->parseSql($sql,$parse);
        return $this->db->query($sql);
    }
526672
public function sanityzeQueryStringBool(array $query)
    {
        foreach ($query as $key => $value) {
            if (\is_bool($value)) {
                $query[$key] = ($value) ? 'true' : 'false';
            }
        }

        return $query;
    }
373750
public function query($query) {

        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            return $this->connection->ExecQuery($query);
        } else {
            $execString = $this->connectionString . '"' . $query . '"';
            $aReturn = Array();
            $inc = $wmiout = $execstatus = null;
            exec($execString, $wmiout, $execstatus);
            $wmiCount = count($wmiout);

            if ($wmiCount > 0) {
                $names = explode('|', $wmiout[1]); // build the names list to dymanically output it
                for ($i = 2; $i < $wmiCount; $i++) { // dynamically output the key:value pairs to suit cacti
                    $data = explode('|', $wmiout[$i]);
                    $j = 0;
                    $inc = $i - 2;
                    $aReturn[$inc] = new \stdClass();
                    foreach ($data as $item) {
                        $jIndex = $j++;
                        if (isset($names[$jIndex])) {
                            $objName = $names[$jIndex];
                            $aReplace = array(':', '_', '  ', '   ', '    ', '     ', '      ', '       ', '        ', '         ', '          ', '           ', '            ');
                            $aReplace2 = array('(null)', 'True', 'False');
                            $preparedData = str_replace($aReplace2, array(null, true, false), str_replace($aReplace, ' ', $item));

                            $aReturn[$inc]->$objName = $preparedData;
                        } else {
                            $j = $jIndex - 1;
                        }
                    }
                }
            }
            $stdObjReturn = (object) $aReturn;

            return $stdObjReturn;
        }
    }
60268
private function _query($query)
    {
        $db = $this->_getConnection();
        if (is_resource($db)) {
            $res = @sqlite_query($db, $query);
            if ($res === false) {
                return false;
            } else {
                return $res;
            }
        }
        return false;
    }
355186
public function fetch($query)
    {
        $db = $this->connection();

        if(method_exists($result = $db->query(rtrim(preg_replace('/\s\s/', ' ', $query), ' ')), 'rowCount')) {

            if($result->rowCount() && $result->setFetchMode($db::FETCH_ASSOC)) {

                return $result->fetchAll();
            }

            return false;
        }
    }
330768
function queryColumn($query)
  {
    $data = [];
    $res = $this->q($query);
    while ($row = $res->fetch_row())
    {
      if ($res->field_count == 1)
        $data[] = $row[0];
      else
        $data[$row[0]] = $row[1];
    }
    $res->close();
    return $data;
  }
1334384
public static function getRow($query)
    {
        $ret = null;

        $res = self::query($query);
        if ($res) {
            if ($row = self::connection()->sql_fetch_assoc($res)) {
                $ret = $row;
            }
            self::free($res);
        }

        return $ret;
    }
771507
public static function exists($query)
    {
        //
        static::applySchema();

        //
        $table = self::getTable();

        //
        $whereArray = [];

        //
        $valuesArray = [];

        //
        if (isset($query['where'])) {
            $whereArray[] = $query['where'];
            unset($query['where']);
        }

        //
        $schema = static::getSchemaFields();

        //
        foreach ($schema as $field) {
            if (isset($query[$field])) {
                $token = ':'.$field;
                $whereArray[] = "`{$field}` = {$token}";
                $valuesArray[$token] = $query[$field];
            }
        }

        $where = count($whereArray) > 0
               ? 'WHERE '.implode(' AND ', $whereArray)
               : '';

        $sql = "SELECT * FROM `{$table}` {$where} LIMIT 1";

        $row = static::getDatabase()->getRow($sql, $valuesArray);

        return $row ? self::create($row) : false;
    }
5277
protected function executeQuery($query)
        {
            $res = @odbc_exec($this->_lnk, $query);
            if(!$res) {
                $error = odbc_errormsg($this->_lnk);
                $this->log('Query failed: '.$error);
                throw new Exception('Executing query failed ' . $error, self::QUERY_FAILED);
            }
            return $res;
        }
877423
public function query($query)
    {

        if (empty($query) || !$this->db) {
            return false;
        }


        // if the resource type is not a mysql link it should try to reconnect
        if (!$this->db->isConnected()) {
            $this->db->ping();
        }

        // the last sql query
        $this->lastSql = (string)$query;


        // if the master is down a select may query the slave but it should not
        // insert anything
        if ($this->slaveConnection === $this->db && stripos(trim($query), 'SELECT') !== 0) {
            throw new DatabaseException(__METHOD__ . ' no Select on slave, abort !!', self::ERR_CONN, self::SEVERITY_LOG, __FILE__, __LINE__);
        }

        // tries execute the query and fetches the result
        $res             = $this->db->getDbAdapter()->query($query);


        try {
            // in cases of errors
            if (!$res) {
                $this->error   = $this->db->getDbAdapter()->getErrorInfo();
                $this->errorno = $this->db->getDbAdapter()->getErrorCode();
                throw new DatabaseException(__METHOD__ . "\nsql: $this->lastSql\nsql_error:$this->error\nsql_errorno:$this->errorno", self::ERR_EXEC, self::SEVERITY_LOG, __FILE__, __LINE__);
            } else {
                $this->insert_id = $this->db->getDbAdapter()->getLastInsertId();
            }
        } catch (DatabaseException $e) {
            if (Config::get('use_exception') !== true) {
                return false;
            }
            throw $e;
        }

        // reset old errors
        $this->error         = '';
        $this->errorno       = 0;
        if ($res && $res instanceof \PDOStatement){
            $this->affected_rows = $this->db->getDbAdapter()->getAffectedRows($res);
        }

        return $res;
    }
1208201
public static function getList($query)
    {
        $ret = array();

        $res = self::query($query);
        if ($res) {
            while ($row = self::connection()->sql_fetch_row($res)) {
                $ret[$row[0]] = $row[1];
            }
            self::free($res);
        }

        return $ret;
    }
717536
public function getArrays($query)
    {
        $this->statement = $this->db->query($query);
        if ($this->statement) {
            $result =  $this->statement->fetchAll(\PDO::FETCH_ASSOC);
            if ($result) {
                return $result;
            }
        }
        return false;
    }
290178
public function executeQuery($query = null)
    {
        $connection = $this->getConnection();
        
        $connection->transaction(function (ConnectionInterface $connection) use ($query) {
            $connection->execute($query);
        });
        
        return $connection->affectedRows();
    }