However im trying to grab the 5 last entrys in a db and echo their first row out on the site, this is how far I've gotten:
<?php
$dsn = "sqlsrv:Server=localhost;Database=blog";
$conn = new PDO($dsn, "*****", "*********");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT TOP 5 FROM blog_posts ORDER BY blogID DESC";
foreach ($conn->query($sql) as $row) {
echo $row[1];
}
?>
error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'FROM'.' in C:\inetpub\wwwroot\dev y\includes\left-menu.php:17 Stack trace: #0 C:\inetpub\wwwroot\dev y\includes\left-menu.php(17): PDO->query('SELECT TOP 5 FR...') #1 C:\inetpub\wwwroot\dev y\index.php(281): include('C:\inetpub\wwwr...') #2 {main} thrown in C:\inetpub\wwwroot\dev y\includes\left-menu.php on line 17