以下是一个简单的PHP商品收藏功能的实现示例,我们将使用一个MySQL数据库来存储商品信息和用户收藏的商品关系。
数据库设计
我们需要设计两个表:`products`(商品表)和`favorites`(收藏表)。

products 表
| 字段名 | 数据类型 | 说明 |
|------------|------------|--------------|
| id | int | 商品ID |
| name | varchar | 商品名称 |
| description| text | 商品描述 |
| price | decimal | 商品价格 |
favorites 表
| 字段名 | 数据类型 | 说明 |
|------------|------------|--------------|
| id | int | 收藏ID |
| user_id | int | 用户ID |
| product_id | int | 商品ID |
PHP代码实现
1. 商品展示页面
```php
// 连接数据库
$mysqli = new mysqli("







