/** * Get assertions by email address * * @param mixed $emailAddresses String (for single user) or array (for multiple users) of user email addresses * @return array */ public function getAssertionsByEmailAddress($emailAddresses) { if (!$this->credentialsSet()) { throw new \Exception('You need to set the credentials first.'); } if (!is_array($emailAddresses)) { $emailAddresses = array($emailAddresses); } $query_params = implode('%20', $emailAddresses); $url = self::PASSPORT_API_ENDPOINT . "assertions?emailAddresses=" . $query_params; if ($this->request_type == 'oauth' && is_a($this->request, 'oauth')) { $this->request->setAuthType(OAUTH_AUTH_TYPE_URI); try { $this->request->fetch($url, null, OAUTH_HTTP_METHOD_GET, array('Content-Type' => 'application/json')); } catch (Exception $e) { error_log($e->getCode()); } $response = json_decode($this->request->getLastResponse()); } else { if ($this->request_type == 'curl' && get_resource_type($this->request) == 'curl') { curl_setopt($this->request, CURLOPT_POST, false); curl_setopt($this->request, CURLOPT_URL, $url); curl_setopt($this->request, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($this->request); $response = json_decode($response); } else { throw new Exception('Unsupported request type'); } } return $response; }
/** * Method to fetch a row from the result set cursor as an associative array. * * @param mixed $cursor The optional result set cursor from which to fetch the row. * * @return mixed Either the next row from the result set or false if there are no more rows. * * @since 1.0 */ protected function fetchAssoc($cursor = null) { if (!empty($cursor) && $cursor instanceof \PDOStatement) { return $cursor->fetch(\PDO::FETCH_ASSOC); } if ($this->prepared instanceof \PDOStatement) { return $this->prepared->fetch(\PDO::FETCH_ASSOC); } }
/** * Get the result from the database. * * @param resource $resource * * @return array */ function db_driver_result($resource) { global $_db; $results = array(); while ($data = $resource->fetch(PDO::FETCH_ASSOC)) { $results[] = $data; } return $results; }
/** * Fetches the result from the resource. * * @return boolean Return `true` on success or `false` if it is not valid. */ protected function _fetchResource() { try { if ($result = $this->_resource->fetch($this->_fetch)) { $this->_key = $this->_iterator++; $this->_current = $result; return true; } } catch (PDOException $e) { return false; } return false; }
/** * @method _parseResults() * @access private * @throws Exception * @desc Parsea los resultados obtenidos en cualquier ejecución de consultas SQL. * @see self::_throwModelException() */ private function _parseResults() { $this->_resultSet = array(); $statementWords = explode(' ', $this->_sqlQuery); if (preg_match('/SELECT/', strtoupper($statementWords[0]))) { $statement = $this->_PDOmySQLConn->prepare($this->_sqlQuery); $statement->execute(); $this->_numRows = $statement->rowCount(); if ((int) $this->_numRows > 0) { while ($row = $this->_resource->fetch(PDO::FETCH_ASSOC)) { array_push($this->_resultSet, $row); } } } else { $this->_numRows = $this->_resource->rowCount(); } }
/** * 将数据查询的其中一行作为数组取出,其中字段名对应数组键值 * * @param resource $resource 查询返回资源标识 * @return array */ public function fetch($resource) { return $resource->fetch(PDO::FETCH_ASSOC); }
/** * Gets the next row from the result and assigns it to the current row * * @return void */ private function advanceCurrentRow() { $type = $this->database->getType(); switch ($this->extension) { case 'ibm_db2': $row = db2_fetch_assoc($this->result); break; case 'mssql': // For some reason the mssql extension will return an empty row even // when now rows were returned, so we have to explicitly check for this if ($this->pointer == 0 && !mssql_num_rows($this->result)) { $row = FALSE; } else { $row = mssql_fetch_assoc($this->result); if (empty($row)) { mssql_fetch_batch($this->result); $row = mssql_fetch_assoc($this->result); } if (!empty($row)) { $row = $this->fixDblibMSSQLDriver($row); } } break; case 'mysql': $row = mysql_fetch_assoc($this->result); break; case 'mysqli': if (!$this->result instanceof stdClass) { $row = mysqli_fetch_assoc($this->result); } else { $meta = $this->result->statement->result_metadata(); $row_references = array(); while ($field = $meta->fetch_field()) { $row_references[] =& $fetched_row[$field->name]; } call_user_func_array(array($this->result->statement, 'bind_result'), $row_references); $this->result->statement->fetch(); $row = array(); foreach ($fetched_row as $key => $val) { $row[$key] = $val; } unset($row_references); $meta->free_result(); } break; case 'oci8': $row = oci_fetch_assoc($this->result); break; case 'pgsql': $row = pg_fetch_assoc($this->result); break; case 'sqlite': $row = sqlite_fetch_array($this->result, SQLITE_ASSOC); break; case 'sqlsrv': $resource = $this->result instanceof stdClass ? $this->result->statement : $this->result; $row = sqlsrv_fetch_array($resource, SQLSRV_FETCH_ASSOC); break; case 'pdo': $row = $this->result->fetch(PDO::FETCH_ASSOC); if (!empty($row) && $type == 'mssql') { $row = $this->fixDblibMSSQLDriver($row); } break; } // Fix uppercase column names to lowercase if ($row && ($type == 'oracle' || $type == 'db2' && $this->extension != 'ibm_db2')) { $row = array_change_key_case($row); } // This is an unfortunate fix that required for databases that don't support limit // clauses with an offset. It prevents unrequested columns from being returned. if (isset($row['flourish__row__num'])) { unset($row['flourish__row__num']); } // This decodes the data coming out of MSSQL into UTF-8 if ($row && $type == 'mssql') { if ($this->character_set) { foreach ($row as $key => $value) { if (!is_string($value) || strpos($key, '__flourish_mssqln_') === 0 || isset($row['fmssqln__' . $key]) || preg_match('#[\\x0-\\x8\\xB\\xC\\xE-\\x1F]#', $value)) { continue; } $row[$key] = self::iconv($this->character_set, 'UTF-8', $value); } } $row = $this->decodeMSSQLNationalColumns($row); // This resets the array pointer so that // current() will work as expected reset($row); } if ($this->unescape_map) { foreach ($this->unescape_map as $column => $type) { if (!isset($row[$column])) { continue; } $row[$column] = $this->database->unescape($type, $row[$column]); } } $this->current_row = $row; }
/** * Fetch row from query result * * @access public * @param resource $resource * @return array */ function fetchRow($resource) { return $resource->fetch(PDO::FETCH_ASSOC); } // fetchRow
/** * Returns the current row * @return array */ function FetchRow() { return $this->recordset->fetch(PDO::FETCH_ASSOC); }
/** * Result - associative array * * Returns the result set as an array * * @return array */ protected function _fetch_assoc() { return $this->result_id->fetch(PDO::FETCH_ASSOC); }
/** * Get the next record as an associative array with fields names as keys. * * @return array(string=>mixed) * @access public */ public function getArray($fetchMode = PDO::FETCH_BOTH) { return is_object($this->_result) ? $this->_result->fetch($fetchMode) : false; }
/** * Return a single row from a query result. This method can be used * if a lot of rows have to be processed one by one, in which case the * DB_RETURN_ROWS and DB_RETURN_ASSOCS return types for the * {@link PhorumDBLayer::interact()} method might consume lots of memory. * * @param resource $res * The result set resource handle. This is the return value of the * method {@link PhorumDBLayer::interact()}, when running a query * with the DB_RETURN_RES return type. * * @param integer $type * A flag, which indicates what type of row has to be returned. * One of {@link DB_RETURN_ASSOC} or {@link DB_RETURN_ROW}, which * will let this method return respectively an associative array * (field name -> value) or an array (field index -> value). * * @return mixed * This method returns either an array containing a single row * or NULL if there are no more rows to retrieve. */ public function fetch_row($res, $type) { if ($type === DB_RETURN_ASSOC) { $row = $res->fetch(PDO::FETCH_ASSOC); } elseif ($type === DB_RETURN_ROW) { $row = $res->fetch(PDO::FETCH_NUM); } else { trigger_error(__METHOD__ . ': Internal error: ' . 'illegal \\$type parameter used', E_USER_ERROR); } return $row ? $row : NULL; }
/** * Convertie un résultat SQL en tableau PHP * La clef du tableau sera celle de la première colonne du résultat SQL * @param resource $paramResult * @return array Tableau PHP */ public static function convertSqlResultKeyAndOneFieldToArray2($paramResult) { $return = NULL; if ($paramResult != NULL) { $paramResult->setFetchMode(PDO::FETCH_OBJ); while ($rows = $paramResult->fetch()) { $return[$rows[0]] = $rows[1]; } return $return; } }
/** * Returns next row from a query result. * * @param resource $sth * PDOStatement resource. * * @return array */ public function fetch($sth) { return $sth->fetch(\PDO::FETCH_ASSOC); }
/** * Go to next row * @param mysqli_result|resource|PDOStatement $result * @return array */ public function nextRow($result) { return $result->fetch(PDO::FETCH_ASSOC); }
/** * Gets the next row from the result and assigns it to the current row * * @return void */ private function advanceCurrentRow() { switch ($this->database->getExtension()) { case 'mssql': // For some reason the mssql extension will return an empty row even // when now rows were returned, so we have to explicitly check for this if ($this->pointer == 0 && !mssql_num_rows($this->result)) { $row = FALSE; } else { $row = mssql_fetch_assoc($this->result); if (empty($row)) { mssql_fetch_batch($this->result); $row = mssql_fetch_assoc($this->result); } if (!empty($row)) { $row = $this->fixDblibMSSQLDriver($row); } } break; case 'mysql': $row = mysql_fetch_assoc($this->result); break; case 'mysqli': $row = mysqli_fetch_assoc($this->result); break; case 'oci8': $row = oci_fetch_assoc($this->result); break; case 'odbc': $row = odbc_fetch_array($this->result); break; case 'pgsql': $row = pg_fetch_assoc($this->result); break; case 'sqlite': $row = sqlite_fetch_array($this->result, SQLITE_ASSOC); break; case 'sqlsrv': $row = sqlsrv_fetch_array($this->result, SQLSRV_FETCH_ASSOC); break; case 'pdo': $row = $this->result->fetch(PDO::FETCH_ASSOC); break; } // Fix uppercase column names to lowercase if ($row && $this->database->getType() == 'oracle') { $new_row = array(); foreach ($row as $column => $value) { $new_row[strtolower($column)] = $value; } $row = $new_row; } // This is an unfortunate fix that required for databases that don't support limit // clauses with an offset. It prevents unrequested columns from being returned. if ($row && ($this->database->getType() == 'mssql' || $this->database->getType() == 'oracle')) { if ($this->untranslated_sql !== NULL && isset($row['flourish__row__num'])) { unset($row['flourish__row__num']); } } // This decodes the data coming out of MSSQL into UTF-8 if ($row && $this->database->getType() == 'mssql') { if ($this->character_set) { foreach ($row as $key => $value) { if (!is_string($value) || strpos($key, '__flourish_mssqln_') === 0 || isset($row['fmssqln__' . $key]) || preg_match('#[\\x0-\\x8\\xB\\xC\\xE-\\x1F]#', $value)) { continue; } $row[$key] = iconv($this->character_set, 'UTF-8', $value); } } $row = $this->decodeMSSQLNationalColumns($row); } if ($this->unescape_map) { foreach ($this->unescape_map as $column => $type) { if (!isset($row[$column])) { continue; } $row[$column] = $this->database->unescape($type, $row[$column]); } } $this->current_row = $row; }
/** * {@inheritDoc} * * @param resource $result result set reference of a query * @return array the next row from the result set as an * associative array in the form column_name => value */ function fetchArray($result) { if (!$result) { return false; } $row = $result->fetch(PDO::FETCH_ASSOC); if (!$this->to_upper_dbms || !$row) { return $row; } $out_row = array(); foreach ($row as $field => $value) { $out_row[strtoupper($field)] = $value; } return $out_row; }
/** * Creates entities from a result set, using findById * * @param resource $result - the DB resource result from the lookup * @access protected * @return array */ protected function loadEntities($result) { $entities = array(); $entity_class = get_class($this); while ($data = $result->fetch(PDB::FETCH_ASSOC)) { $entity = $this->createEntity($entity_class); if ($entity->loadFromArray($data)) { $entities[] = $entity; } } return $entities; }
/** * Return parameters from the statment with dynamic number of parameters. * * @param resource $stmt Statement. * @param array $params Parameters. */ public static function bindResults($stmt) { $resultSet = array(); $metaData = $stmt->result_metadata(); $fieldsCounter = 0; while ($field = $metaData->fetch_field()) { if (!isset($resultSet[$field->table])) { $resultSet[$field->table] = array(); } $resultSet[$field->table][$field->name] = $fieldsCounter++; $parameterName = "variable" . $fieldsCounter; //$field->name; ${$parameterName} = null; $parameters[] =& ${$parameterName}; } call_user_func_array(array($stmt, 'bind_result'), $parameters); if ($stmt->fetch()) { foreach ($resultSet as &$tableResult) { foreach ($tableResult as &$fieldValue) { $fieldValue = $parameters[$fieldValue]; } } return $resultSet; } self::checkDbError($stmt); return null; }