I want to show data from sql in my php page but I get this error:
"Error: SQLSTATE[42000]: Syntax error or access violation: 156 [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'user'. (SQLExecute[156] at ext\pdo_odbc\odbc_stmt.c:258)"
This is the code I am using and when I check if the odbc:odbc2sqlserver connection it says 'true'.
I searched on other questions but I could not find working answer.
<tr>
<td>
<div id="wrapper">
<?php
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>UserID</th><th>Username</th><th>Password</th><th>Beheerder</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Taaltrainer";
try {
$conn = new PDO("odbc:odbc2sqlserver");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM user");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>
</div>
</td>
</tr>