I am trying to use PDO in Linux to connect to MSSQL Server. There is a DB schema containing some Tables and Views.
$db = new PDO("dblib:host=$host:$port;dbname=$dbname", $username, $password);
// Working: select from a table
$sql = "SELECT id FROM some_table";
$stmt = $db->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
// NOT Working: select from a view
$sql = "SELECT id FROM some_view";
$stmt = $db->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
I found the function PDOStatement::fetchAll()
is unable to return results when selecting from a View, but works fine in Table.
Given that the account I logged in to SQL Server has permissions on both View and Table, what else did I miss?
$stmt->execute();
returns FALSE
on the View's case; returns TRUE
on Table's case.