docker run -d --name db --network lnmp -p 3306:3306 -v /opt/db_data:/var/lib/mysql -v /opt/db_conf:/etc/mysql --env MARIADB_USER=admin --env MARIADB_PASSWORD=1 --env MARIADB_ROOT_PASSWORD=1 mariadb:10.5
## 检测
create table student(id int not null primary key auto_increment comment '主键ID',
name varchar(20) not null comment '姓名',
age int not null comment '年龄')engine=InnoDB default charset=utf8 comment '学生数据表';
insert into student(name, age) values('小明', 18);
insert into student(name, age) values('啊俊', 28);
-------------------------------------
<?php
$dsn='mysql:dbname=test;host=mysql';$user='root';$password='123456';
try {$dbh= new PDO($dsn, $user, $password);$sql='SELECT * FROM student where id=?';$sth=$dbh->prepare($sql);$sth->execute([2]);$result=$sth->fetch(PDO::FETCH_ASSOC);
var_dump($result);} catch (PDOException $e){echo'Error: '.$e->getMessage();}