Problems encountered in connecting to the database with mac php7

1. The company's computer is a pure version, no other integrated environments xampp, xmpp, etc. are installed. The built-in php is 7, and nginx is installed.

The server made of nginx, executes the php program, and reports an error when accessing the php program, because there is no configuration file, because it is a new system, you need to manually add it yourself, in fact, copy

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;
        }
    }

The php directory that comes with mac is in

cd /private/etc/ , enter the directory, ls will see many files with default suffix, you need to copy these files to remove the default default

cp (-r/-R) oldfile newfile

then execute

sudo php-fpm -D

This will allow php to run.

Then start the nginx server.

Now I use PHP to connect to the database, because php7 all uses mysqli

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

The point is that the port number is 3306. I haven't added it before and it has been reporting an error. It's fine to add it.

There is also a problem that Chinese characters cannot be inserted, which has not been solved

 

2. The computer at home is the integrated environment xampp, and the project can be placed in a fixed directory. This can be accessed without adding a port number. There is also the problem of garbled Chinese characters. This can be inserted, but it is garbled.

 

3. You can use the Apache service that comes with the mac to start php,

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

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324456433&siteId=291194637