sqlsrv_fetch_array

(No version information available, might only be in Git)

sqlsrv_fetch_arrayReturns a row as an array

Beschreibung

sqlsrv_fetch_array(
    resource $stmt,
    int $fetchType = ?,
    int $row = ?,
    int $offset = ?
): array

Returns the next available row of data as an associative array, a numeric array, or both (the default).

Parameter-Liste

stmt

A statement resource returned by sqlsrv_query or sqlsrv_prepare.

fetchType

A predefined constant specifying the type of array to return. Possible values are SQLSRV_FETCH_ASSOC, SQLSRV_FETCH_NUMERIC, and SQLSRV_FETCH_BOTH (the default).

A fetch type of SQLSRV_FETCH_ASSOC should not be used when consuming a result set with multiple columns of the same name.

row

Specifies the row to access in a result set that uses a scrollable cursor. Possible values are SQLSRV_SCROLL_NEXT, SQLSRV_SCROLL_PRIOR, SQLSRV_SCROLL_FIRST, SQLSRV_SCROLL_LAST, SQLSRV_SCROLL_ABSOLUTE and, SQLSRV_SCROLL_RELATIVE (the default). When this parameter is specified, the fetchType must be explicitly defined.

offset

Specifies the row to be accessed if the row parameter is set to SQLSRV_SCROLL_ABSOLUTE or SQLSRV_SCROLL_RELATIVE. Note that the first row in a result set has index 0.

Rückgabewerte

Returns an array on success, null if there are no more rows to return, and false if an error occurs.

Beispiele

Beispiel #1 Retrieving an associative array.

<?php
$serverName 
"serverName\instanceName";
$connectionInfo = array( "Database"=>"dbName""UID"=>"username""PWD"=>"password");
$conn sqlsrv_connect$serverName$connectionInfo );
if( 
$conn === false ) {
    die( 
print_rsqlsrv_errors(), true));
}

$sql "SELECT FirstName, LastName FROM SomeTable";
$stmt sqlsrv_query$conn$sql );
if( 
$stmt === false) {
    die( 
print_rsqlsrv_errors(), true) );
}

while( 
$row sqlsrv_fetch_array$stmtSQLSRV_FETCH_ASSOC) ) {
      echo 
$row['LastName'].", ".$row['FirstName']."<br />";
}

sqlsrv_free_stmt$stmt);
?>

Beispiel #2 Retrieving a numeric array.

<?php
$serverName 
"serverName\instanceName";
$connectionInfo = array( "Database"=>"dbName""UID"=>"username""PWD"=>"password");
$conn sqlsrv_connect$serverName$connectionInfo );
if( 
$conn === false ) {
    die( 
print_rsqlsrv_errors(), true));
}

$sql "SELECT FirstName, LastName FROM SomeTable";
$stmt sqlsrv_query$conn$sql );
if( 
$stmt === false) {
    die( 
print_rsqlsrv_errors(), true) );
}

while( 
$row sqlsrv_fetch_array$stmtSQLSRV_FETCH_NUMERIC) ) {
      echo 
$row[0].", ".$row[1]."<br />";
}

sqlsrv_free_stmt$stmt);
?>

Anmerkungen

Not specifying the fetchType or explicitly using the SQLSRV_FETCH_TYPE constant in the examples above will return an array that has both associative and numeric keys.

If more than one column is returned with the same name, the last column will take precedence. To avoid field name collisions, use aliases.

If a column with no name is returned, the associative key for the array element will be an empty string ("").

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Spielplan für 4 Gruppen zu je 6 Teams auf 2 Feldern

Hey, hallöchen! Du musst die Spiele so durchgehen, dass die Platzierung kontrolliert wechseln, dass jedes Team auf den Plätzen spielt. Hier ist ...

Geschrieben von derH0st am 10.06.2024 14:26:06
Forum: PHP Developer Forum
Does Google ignore common words?

Our website is optimized for "mock web services" and "web service mocks," but Google Webmaster doesn't recognize "web services" (or its variations ...

Geschrieben von TahuluLimia am 10.06.2024 12:26:02
Forum: Webmaster
How to overcome Safari's iframe cookie block?

Seeking an elegant solution for cross-domain cookie sharing in my project. Safari's default iframe session cookie block is a hurdle. While the san ...

Geschrieben von BrovtalGemini am 10.06.2024 10:14:21
Forum: HTML, JavaScript, AJAX, jQuery, CSS, Bootstrap, LESS
Helfen! Doppelte Bestelleinträge in meiner Verkaufstabelle

Identifizieren Sie doppelte Einträge: Manuelle Überprüfung: Durchsuchen Sie die Tabelle "Sales" nach doppelten Einträgen (zeitaufwändig & u ...

Geschrieben von LillianFelly am 04.06.2024 12:46:18
Forum: SQL / Datenbanken