我正在尝试使用类编写select,但它不起作用

I want to call 2 column from DB newsId and title and then print it.

My code looks like this:

class edit
{
    private $db;

    public function __construct()
    {
        $this->db = new Connection();
        $this->db = $this->db->dbConnect();
    }


    public function news($neswID, $title)
    {
        $sql = $this->db->prepare("SELECT newsID, title FROM `news`");

        $result = $sql->execute(array($newsID, $title));

        while ($sql->fetch($result)) {
            print $neswID . '<br>' . $title;
        }

    }
}

and I call this class like this:

include_once "test.php";
$object= new edit();
$object->news($newsID, $title);

I am really new, thank you for help.

change you code to

$sql->execute();

while($row = $sql->fetch(PDO::FETCH_ASSOC)){
  print $row['newsId'] .'<br>'. $row['title'] .'<br>';
}

prepare() return a PDOStatement

Your while loop should be like this, as your column name are newsID and title

$sql->execute(); 
while($row = $sql->fetch(PDO::FETCH_ASSOC)){
  echo $row['newsID'].'==='.$row['title'];
}