Learn how to query a database using PHP,然后使用如下查询从数据库中获取数据:
SELECT * FROM media;
扩展解决方案:
$db = new mysqli('localhost', 'user', 'pass', 'demo');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "SELECT * FROM media;";
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo $row['id'] . ', ' . $row['name'] . ', ' . $row['phone'] . ', ' . $row['email'] . ', ' . $row['address'] . '
';
}
每个字段都将在$row数组中用于earch结果行.