public function getAll($table) {
$stmt = $this->pdo->query('SELECT * '.'FROM '.$table );
$recs = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$recs[] = [
'id' => $row['id'],
'name' => $row['name'],
'score'=> $row['score']
];
}
return $recs;
}
PHP 的column name都要寫明 不能虛擬化。
反觀python 超虛擬的:
def getAll(table):
cur.execute("SELECT * from "+table)
rows = cur.fetchall()
for row in rows:
print row[0]
print " ", row[1]
print " ", row[2]
PHP 是否確實如此?還是我學藝不精?