1. 环境准备

在开始之前,请确保已经安装了PHP环境,并且有一个MySQL数据库服务器运行。

环境说明
PHP确保PHP版本支持PDO或mysqli扩展
MySQL确保MySQL数据库和用户已创建

2. 创建连接

我们需要创建一个到MySQL数据库的连接。

```php

$host = 'localhost';

$db = 'test';

$user = 'root';

$pass = '';

$charset = 'utf8mb4';

$dsn = "