警告:PDO: __construct()期望至少有一个参数,在C:\xampp\htdocs\Svetaine\函数中给出。php在43行

时间:2023-01-21 19:22:52

Hello I'm new on PDO and have a problem, can somoeone help me?

你好,我是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;
}

Thanks for helping Error line $dbh->query($sql);

感谢帮助错误行$dbh->查询($sql);

1 个解决方案

#1


1  

try this, replace your informations database.

试试这个,替换你的信息数据库。

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

#1


1  

try this, replace your informations database.

试试这个,替换你的信息数据库。

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