wpdb::get_row PHP Method

get_row() public method

Executes a SQL query and returns the row from the SQL result.
Since: 0.71
public get_row ( string | null $query = null, string $output = OBJECT, integer $y ) : mixed
$query string | null SQL query.
$output string Optional. one of ARRAY_A | ARRAY_N | OBJECT constants. Return an associative array (column => value, ...), a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively.
$y integer Optional. Row to return. Indexed from 0.
return mixed Database query result in format specified by $output or null on failure
    public function get_row($query = null, $output = OBJECT, $y = 0)
    {
        $this->func_call = "\$db->get_row(\"{$query}\",{$output},{$y})";
        if ($query) {
            $this->query($query);
        } else {
            return null;
        }
        if (!isset($this->last_result[$y])) {
            return null;
        }
        if ($output == OBJECT) {
            return $this->last_result[$y] ? $this->last_result[$y] : null;
        } elseif ($output == ARRAY_A) {
            return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null;
        } elseif ($output == ARRAY_N) {
            return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null;
        } elseif (strtoupper($output) === OBJECT) {
            // Back compat for OBJECT being previously case insensitive.
            return $this->last_result[$y] ? $this->last_result[$y] : null;
        } else {
            $this->print_error(" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N");
        }
    }

Usage Example

コード例 #1
0
ファイル: Database.php プロジェクト: JBZoo/CrossCMS
 /**
  * {@inheritdoc}
  */
 public function fetchArray($sql)
 {
     $sql = $this->_prepareSql($sql);
     $result = $this->_db->get_row($sql, ARRAY_N);
     $this->_checkError();
     return $result;
 }
All Usage Examples Of wpdb::get_row