N.1 Nginx的命令操作
win-nginx发布部署和命令.note
N.2 PHP安装和启动
win-php部署和命令.note
N.3 Nginx配置
127.0.0.1:9000 是php启动程序地址的通信端口。 |
location / { root html; index index.html index.html default.html default.htm index.php default.php; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } |
N.4 访问测试
mydata.php 文件内容 |
<?php header("Access-Control-Allow-Origin:*");//解决跨域请求问题 header('Access-Control-Allow-Methods:POST'); header('Access-Control-Allow-Headers:x-requested-with, content-type'); header("content-Type: text/json; charset=utf-8");//字符编码设置 $servername = "localhost"; $username = "root"; $password = "a"; $dbname = "test"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 连接失败 if ($conn->connect_error) { //->调用方法或属性的意思 die("连接失败: " . $conn->connect_error); } //查询数据 $sql = "SELECT month,num FROM wc"; $result = $conn->query($sql); $arr = array(); // 遍历赋值 if ($result->num_rows > 0) { // 行数大于0 while($row = $result->fetch_assoc()) { array_push($arr,$row); // 把row插入到arr里面 } } else { echo "没有数据"; } // 输出json echo json_encode($arr,JSON_UNESCAPED_UNICODE);//json编码 //关闭连接 $conn->close(); ?> |
页面每次刷新的时候就会更新数据库。