|
PDOStatement::fetchFetches the next row from a result set Beschreibung
public mixed PDOStatement::fetch
([ int
$fetch_style
[, int $cursor_orientation = PDO::FETCH_ORI_NEXT
[, int $cursor_offset = 0
]]] )
Fetches a row from a result set associated with a PDOStatement object. The
Parameter-Liste
Rückgabewerte
The return value of this function on success depends on the fetch type. In
all cases, Beispiele
Beispiel #1 Fetching rows using different fetch styles
<?phpDas oben gezeigte Beispiel erzeugt folgende Ausgabe:
PDO::FETCH_ASSOC: Return next row as an array indexed by column name
Array
(
[name] => apple
[colour] => red
)
PDO::FETCH_BOTH: Return next row as an array indexed by both column name and number
Array
(
[name] => banana
[0] => banana
[colour] => yellow
[1] => yellow
)
PDO::FETCH_LAZY: Return next row as an anonymous object with column names as properties
PDORow Object
(
[name] => orange
[colour] => orange
)
PDO::FETCH_OBJ: Return next row as an anonymous object with column names as properties
kiwi
Beispiel #2 Fetching rows with a scrollable cursor
<?phpDas oben gezeigte Beispiel erzeugt folgende Ausgabe: Reading forwards: 21 10 5 16 0 5 19 20 10 Reading backwards: 19 20 10 16 0 5 21 10 5 Beispiel #3 Construction order When objects are fetched via PDO::FETCH_CLASS the object properties are assigned first, and then the constructor of the class is invoked. If PDO::FETCH_PROPS_LATE is also given, this order is reversed, i.e. first the constructor is called, and afterwards the properties are assigned.
<?phpDas oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie: I am Alice. I am Alice. I don't have a name yet. I am Bob. Siehe auch
|