一站式网上办事大厅




<?php
// 示例代码:一网通办平台的用户信息查询功能
function getUserInfo($userId) {
$url = "http://government-service.com/api/userinfo";
$data = array('userId' => $userId);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
return json_decode($result, true);
}
// 使用示例
$userInfo = getUserInfo(123456);
echo "User Name: " . $userInfo['name'] . "\n";
echo "User Email: " . $userInfo['email'] . "\n";
// 数据库连接配置
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "government_service";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// SQL 查询语句
$sql = "SELECT * FROM user WHERE id=123456";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// 输出数据
while($row = $result->fetch_assoc()) {
echo "Name: " . $row["name"]. " - Email: " . $row["email"]. "
";
}
} else {
echo "0 结果";
}
$conn->close();
?>