警告:PDO :: __ construct()期望在第43行的C:\ xampp \ htdocs \ Svetaine \ functions.php中给出至少1个参数0

时间:2014-10-13 18:51:05

标签: php mysql pdo

您好,我是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);

1 个答案:

答案 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;
}