以下是一个简单的实例,展示如何使用PHP来处理NG(Angular)网站的数据交互。
1. NG前端代码
在NG中,我们通常会使用HTTPClient模块来发送HTTP请求。

```typescript
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private http: HttpClient) { }
getData() {
return this.http.get('http://example.com/api/data');
}
}
```
2. PHP后端代码
在PHP中,我们需要创建一个API来接收请求并返回数据。
```php
// index.php
// 模拟数据库连接
$conn = new mysqli("









