我想從DB newsId和標題調用2列,然後打印它。我想寫選擇使用類,但它不工作
我的代碼如下所示:
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;
}
}
}
,我調用這個類是這樣的:
include_once "test.php";
$object= new edit();
$object->news($newsID, $title);
我真的很新的,謝謝你的幫助。
什麼條件獲得newsId和title。當你傳遞給你的函數 – Roopendra
你在'public function news()'中拼寫錯了'$ neswID'。它應該是'$ newsID'。 – SamV
「Connection」類建立什麼類型的DB連接?我希望你使用PDO – MBaas