简体   繁体   中英

Pull data from mssql to array - PHP

I pull data from the mssql database. I want to assign the data I have captured as an array. So I want to assign more than one table value to the result. Currently, it only assigns 1 value. When I make $ results [], I can't print. I converted it to an array so I can assign more than one data, but it doesn't work.

<?php
...
$conn = sqlsrv_connect( $serverName, $connectionInfo );

$sql = "...";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}


while( $row = sqlsrv_fetch_array($stmt) ) {

    $destekCevap = $row['destekcevap_..'];
    $destekCevapFoto = $row['destekcevap_...'];

    $results = Array("destekcevap_.." => $destekCevap, "destekCevapFoto" => $destekCevapFoto);

}

    echo json_encode($results);

sqlsrv_free_stmt($stmt);
?>

Initialize the array above the while-loop and assign new values in the loop like this:

$results = array();

while( $row = sqlsrv_fetch_array($stmt) ) {

    $destekCevap = $row['destekcevap_..'];
    $destekCevapFoto = $row['destekcevap_...'];

    $results[] = "your values";

}

Cheers,

Niklas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM