您好,我是PDO的新手并遇到问题,有人可以帮帮我吗?
public function Counters()
{
$dbh = new PDO();
$sql = "SELECT * FROM news ORDER BY id";
$dbh->query($sql);
echo '
<div class="row2">
<h1>Svarbios naujienos:</h1>
<p></p>';
$count = $c->rowCount();
$s = 0;
if($count > 0)
{
foreach ($dbh->query($sql) as $row) {
echo '
<p>'.$row['Naujiena'].'</p>';
}
}
echo '
</div>
<div class="row2img">
<img src="images/slide2.jpg" width="864" height="210">
</div>
';
return 1;
}
感谢您的帮助 错误行$ dbh-&gt; query($ sql);
答案 0 :(得分:1)
试试这个,替换你的信息数据库。
public function Counters()
{
$dbh = new PDO("mysql:host=localhost;dbname=dbname", "dbuser", "dbpass");
$sql = "SELECT * FROM news ORDER BY id";
$dbh->query($sql);
echo '
<div class="row2">
<h1>Svarbios naujienos:</h1>
<p></p>';
$count = $c->rowCount();
$s = 0;
if($count > 0)
{
foreach ($dbh->query($sql) as $row) {
echo '
<p>'.$row['Naujiena'].'</p>';
}
}
echo '
</div>
<div class="row2img">
<img src="images/slide2.jpg" width="864" height="210">
</div>
';
return 1;
}