<style>
table{
border:1px solid gray;
Border-collapse:collapse;
width:85%;
margin:0 Auto;
Text-align:center;
}
Table th, table td{
border:1px solid gray;
}
</style>
<?php
/**
* Created by Phpstorm.
* User:administrator
* DATE:2017/8/1
* Time : 17:18
*/
//Normal connection database
$pdo = new PDO (' mysql:host=localhost;port=3306;charset=utf8;dbname=pg137 ', ' root ', ' );
//password can be omitted
//$pdo = new PDO (' Mysql:host=localhost;port=3306;charset=utf8;dbname=pg37 ', ' root ');
User name can not omit
//$pdo = new PDO (' Mysql:host=localhost;port=3306;charset=utf8;dbname=pg37 ');
The address can be changed
//$pdo = new PDO (' Mysql:host=127.0.0.1;port=3306;charset=utf8;dbname=pg37 ', ' root ', ');
Allow local access only
//$pdo = new PDO (' Mysql:host=255.21.23.12;port=3306;charset=utf8;dbname=pg37 ', ' root ', ');
Var_dump ($PDO);
//Get object
$ps = $pdo->query (' select * from Xuesheng ');
Var_dump ($ps);
Get result set PDO::FETCH_ASSOC only contains column name label
Var_dump ($ps->fetchall (PDO::FETCH_ASSOC));
$arr = Array ();
if ($ps) {
foreach ($ps as $row) {
Array_push ($arr, $row);
}
}
Echo ' <table> ';
Echo ' <tr><th> serial number </th><th> name </th><th> gender </th><th> phone number </th> <th> Home Address </th><th> operations </th></tr> ';
foreach ($arr as $val) {
Echo ' <tr> ';
Echo ' <td> ' $val [0]. ' </td><td> '. $val [1]. ' </td><td> '. $val [2]. ' </td><td> '. $val [3]. ' </td><td> '. $val [4]. ' </td>
</td><td><a href= "updatestu.php?sid=". $val [0]. ' > Modify </a>--<a href= ' updatestu1.php?sid= '. $val [0]. ' > Add </a></td> ';
Echo ' </tr> ';
}
Echo ' </table> ';
Shut down
$pdo = null;
PDO Connection Database