我试图让它在标题链接中显示最新公告。 我已经试过这样做,现在我只是想获得它甚至返回变量,它不会......获取信息的PHP函数
的functions.php
<?php
require("common.php");
function getAnnouncements() {
$query = "SELECT * FROM announcements";
try {
global $db;
// Execute the query against the database
$stmt = $db->prepare($query);
$result = $stmt->execute();
echo $result['title'];
}
catch(PDOException $ex) {
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
}
?>
的index.php
<div class="announcement">
<div class="container">
Latest Announcements: <?php getAnnouncements(); echo "<a href=''></a>" ?>
</div>
</div>
是的,我包括在顶部的文件,并没有拼写错误。
http://php.net/manual/en/pdostatement.execute.php - 执行返回什么? – 2014-10-17 22:14:58
'var_dump($ result);' – DarkSide 2014-10-17 22:16:32