Complete Mysqli Result - Fetch with Example

Mysqli Fetch result array result structure.

Mysqli Fetch All

$stmt->fetch_all();

$stmt = $mysqli->query("SELECT * ....");
        $s = 10;
        if($stmt->num_rows>0) {
            while($row = $stmt->fetch_all()) {
                $s = $row;
            }
        }


Result Array Structure
Array
(
    [0] => Array
        (
            [0] => 262
            [1] => com/acer
            [2] => Iconia Tab A210
            [3] => acer_iconia_tab_a210-5066.php
            [4] => no
        )

)

Mysqli Fetch Array

$stmt->fetch_array();

$stmt = $mysqli->query("SELECT * ....");
        $s = 10;
        if($stmt->num_rows>0) {
            while($row = $stmt->fetch_array()) {
                $s = $row;
            }
        }


Result Array Structure
Array
(
    [0] => 262
    [id] => 262
    [1] => com/acer
    [brand] => com/acer
    [2] => Iconia Tab A210
    [name] => Iconia Tab A210
    [3] => acer_iconia_tab_a210-5066.php
    [url] => acer_iconia_tab_a210-5066.php
    [4] => no
    [is_spec_downloaded] => no
)

Mysqli Fetch Assoc

$stmt->fetch_assoc();

$stmt = $mysqli->query("SELECT * ....");
        $s = 10;
        if($stmt->num_rows>0) {
            while($row = $stmt->fetch_assoc()) {
                $s = $row;
            }
        }


Result Array Structure
Array
(
    [id] => 262
    [brand] => com/acer
    [name] => Iconia Tab A210
    [url] => acer_iconia_tab_a210-5066.php
    [is_spec_downloaded] => no
)

Mysqli Fetch Field

$stmt->fetch_field();

$stmt = $mysqli->query("SELECT * ....");
        $s = 10;
        if($stmt->num_rows>0) {
            while($row = $stmt->fetch_field()) {
                $s = $row;
            }
        }



Result Array Structure
stdClass Object
(
    [name] => is_spec_downloaded
    [orgname] => is_spec_downloaded
    [table] => rawphonenameurl
    [orgtable] => rawphonenameurl
    [def] => 
    [db] => compare
    [catalog] => def
    [max_length] => 2
    [length] => 3
    [charsetnr] => 8
    [flags] => 257
    [type] => 254
    [decimals] => 0
)

Mysqli Fetch Object

$stmt->fetch_object();

$stmt = $mysqli->query("SELECT * ....");
        $s = 10;
        if($stmt->num_rows>0) {
            while($row = $stmt->fetch_object()) {
                $s = $row;
            }
        }


Result Array Structure
stdClass Object
(
    [id] => 262
    [brand] => com/acer
    [name] => Iconia Tab A210
    [url] => acer_iconia_tab_a210-5066.php
    [is_spec_downloaded] => no
)


Mysqli Fetch Row

$stmt->fetch_row();

$stmt = $mysqli->query("SELECT * ....");
        $s = 10;
        if($stmt->num_rows>0) {
            while($row = $stmt->fetch_row()) {
                $s = $row;
            }
        }


Result Array Structure
Array
(
    [0] => 262
    [1] => com/acer
    [2] => Iconia Tab A210
    [3] => acer_iconia_tab_a210-5066.php
    [4] => no
)

3 Comments

Previous Post Next Post