ICoded
ICoded

Reputation: 341

PHP sql query does not return table content

I want to execute a simple sqlsrv_query query in php. To do so, I installed the MS Drivers and was able to establish a connection to my DB (SQL Server Management Studio 18.9.2). What I don´t understand is the message Resource id #3, which I believe is neither an failure or error. I expect a raw echo / print_r of the table content. What do I miss?

$sql = "SELECT * FROM nodes";
$stmt = sqlsrv_query($conn, $sql);

if ($stmt === false) {
    die (print_r(sqlsrv_errors(), true));
} else {
    while ($row = sqlsrv_fetch($stmt))
    print_r($row);
    print_r($stmt);
    echo "<br />Statement executed";
}

The table looks like:

enter image description here

Error I get:

enter image description here

Upvotes: 0

Views: 41

Answers (1)

Viktor T&#246;r&#246;k
Viktor T&#246;r&#246;k

Reputation: 1319

Try to use sqlsrv_fetch_array statement instead of the sqlsrv_fetch.

while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))
{
    // print_r($row);
    print($row["nodes"] . "<br>");
}

Upvotes: 1

Related Questions