PHP读取mysql中的数据
<!DOCTYPE HTML> <html> <head> <title> PHP动态读取mysql中的数据 </title> <meta charset="gb2312"> </head> <body> <h1>用户管理:</h1> <?php //连接数据库 $pdo=new PDO('mysql:host=localhost;dbname=ajax_stydy','root','root'); $pdo->exec('set names gb2312'); $sql="select * from user"; $smt=$pdo->query($sql); $rows=$smt->fetchAll(PDO::FETCH_ASSOC); //获取数据 ?> <table width="700px" border="1px" cellspacing="0px"> <tr> <th>ID</th> <th>用户名</th> <th>密码</th> <th>操作</th> </tr> <?PHP foreach($rows as $row){ echo"<tr>"; echo"<td>{$row['Id']}</td>"; echo"<td>{$row['username']}</td>"; echo"<td>{$row['pass']}</td>"; echo"<td><a href='delete.php?id={$row['Id']}'>删除用户</a></td>"; echo"</tr>"; } ?> </table> </body> </html>