zoukankan      html  css  js  c++  java
  • mac php7 连接数据库遇到的问题

    1. 公司的电脑是纯净版的,没有安装其他的集成环境xampp,xmpp等,自带的php是7,安装了nginx。

    用nginx做的服务器,执行php的程序,访问php程序时报错,因为还没有配置文件,因为是新系统,需要自己手动添加,其实是复制

    server {
            listen       8060;
            server_name  localhost.agent.pz.simuhao.com agent.pz.simuhao.com;
    
            charset utf-8;
    
            #access_log  logs/host.access.log  main;
            root   /Volumes/D/git/xxx/public;
            index  index.html index.php index.htm;
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   /Volumes/D/oakgit/www;
            }
    
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ .php {
    root           /Volumes/D/git/xxx/public;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info ^(.+.php)(.*)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
                include        fastcgi.conf;
            }
    
            location / {
                    try_files $uri /index.php$uri?$query_string;
            }
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            location ~ /.ht {
                deny all;
            }
        }

    mac自带的php目录在

    cd /private/etc/ ,进入到目录下面,ls会看到很多default后缀的文件,需要将这些文件复制去掉后面的default

    cp (-r/-R) oldfile newfile

    然后执行

    sudo php-fpm -D

    这样php就能运行了。

    然后启动nginx服务器。

    现在是用PHP连接数据库,因为是php7所有使用mysqli

    <?php
        $mysqli = new mysqli('localhost:3306', 'root', '123456', 'support');
        if ($mysqli->connect_error) {
            die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
        }
        echo "连接成功";
        $mysqli->close();
    ?>

    重点是端口号 3306,之前没加一直报错,加上就好了。

    还有一个汉字没办法插入的问题,没有解决

    2. 家里的电脑是集成环境xampp, 项目放到固定的目录即可,这个不用加端口号也能访问,一样有汉字乱码的问题,这个能插入,但是是乱码。

    3. 可以用mac自带的Apache服务启动php,

    https://blog.csdn.net/wj_november/article/details/51417491 

  • 相关阅读:
    mysql5.7安装
    win10 安装docker
    快速去水印(win10换图3D工具)
    爬虫---国家食品药品监督管理总局
    食品伙伴网爬虫
    驴妈妈旅游爬虫
    天气预测(CNN)
    ConcurrentDictionary线程不安全么,你难道没疑惑,你难道弄懂了么?
    C#线程篇---线程池如何管理线程(6完结篇)
    C#线程篇---Task(任务)和线程池不得不说的秘密(5)
  • 原文地址:https://www.cnblogs.com/wenwenli/p/8806836.html
Copyright © 2011-2022 走看看