所以我想要的功能,我可以像下面我怎麼能作出這樣的訪問行
$user->userData('username');
獲取數據的功能這裏是我當前的功能
public function userData() {
$username = "username";
$query = $this->db->prepare("SELECT * FROM users WHERE username=:username");
$query->execute(['username' => $username]);
$row = $query->fetch(PDO::FETCH_ASSOC);
return $row;
}
的問題是,當我打電話的功能,它的返回此錯誤:
Notice: Array to string conversion in /Applications/XAMPP/xamppfiles/htdocs/php/home.php on line 9 Arrays
9號線是
echo $user->userData('username');
問題在哪裏? – 0x13a
編輯帖子,包括錯誤。 – Alam
但是你正在打印一個數組作爲字符串,你應該使用'print_r'打印數組數據 – 0x13a