<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>demo</title>
<head>
<body>
<form method="get" action="">
<input type="text" name="id">
<button>提交</button>
</form>
<br>
<?php
function dd($params)
{
echo "<pre>";
var_dump($params);
echo "</pre>";
die;
}
function mysqlConnect(){
$config =[
'host'=>'127.0.0.1',
'account'=>'root',
'password'=>'021104',
'dbname'=>'test',
'charset'=>'utf-8'
];
$connect = new mysqli($config['host'],$config['account'],$config['password'],$config['dbName']);
if($connect->connect_error){
dd(‘数据库连接失败’);
}
$connect->set_charset($config['charset']);
return $connect;
}
$id = isset($_GET['id'])?(int)$_GET['id']:0;
if($id){
$sql = sprintf('SELECT * FROM '%s 'WHERE' id '=%d','t1',$id);
$connect = mysqlConnect();
$res = $connect->query($sql);
$result = [ ];
while($row = $res->fetch_object())
{
$result[ ] = $row;
}
$row = reset($result);
echo $row->name;
}
?>
</body>
</html>
网友评论