记录php遇到的那些坑

首先按照网上指南搭建php、阿帕奇、数据库环境。

具体放上网站

http://www.cnblogs.com/ypr-09-23/p/10797153.html  这是mysql安装指南

需要注意的是学校使用的数据库是有图形界面的,这个安装完后一样使用,只是看起来别扭而已。

其中my.ini文件,只有三个地方需要修改(标记备注的地方)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_bin
init_connect='SET NAMES utf8mb4'
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = D:\搜狗高速下载\mysql-8.0.16-winx64   //这里是你自己安装mysql的文件地址
datadir = D:\MySQL\Database                    //用来存放数据库文件的地址,自己要新建一个哟
port = 3306                                    //端口号默认不用修改
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 16M
read_rnd_buffer_size = 16M 
sql_mode=NO_EN

2.接下来得去下载阿帕奇

https://jingyan.baidu.com/article/d8072ac47baf0eec95cefdca.html 地址,不多说

其中最重要的配置文件是conf文件夹中的httpd.conf,注意端口号,详细的一会说。

3.下载phpD:\php-7.3.5-nts-Win32-VC15-x64

https://jingyan.baidu.com/article/c33e3f488e7f38ea15cbb530.html下载方式

在选择文件版本时有一个Thread Safe 注意前面是否有Non,要下载不带Non的!!!

 4.连接数据库,这时候你得保证自己的php文件可以正常使用。

在你的D:\Apache24\htdocs下建一个php文件,打开浏览器

输入http://localhost:8080/xxxxx.php  ,在你编程正确的基础上,网页能正常显示结果

mysql之前说过怎么下载了,上边有网址。

最重要的是测试是否连接数据库,步骤如下:

<?php
//设定字符集
header('Content-Type:text/html;charset=utf-8');
 
//开启调试模式
define('DB_DEBUG',true);
 
//加载数据库操作函数库
 
require '.\lib\db_function.php';
 
//初始化数据库
$link = db_init(array(
    'host' => '127.0.0.1', //主机名
    'user' => 'root',      //用户名
    'password' => '123456',//密码
    'dbname' => 'stumanager',  //数据库
    'charset' => 'utf8'    //字符集
)); 
 
//接收GET变量
function input_get($name){
    return isset($_GET[$name]) ? $_GET[$name] : '';
}
//接收POST变量
function input_post($name){
    return isset($_POST[$name]) ? $_POST[$name] : '';
}
 
/**
 * 对字符串数据进行过滤
 * @param string $data 待转义字符串
 * @return string 转义后的字符串
 */
function filter($data,$func=array('trim','htmlspecialchars')){
    foreach($func as $v){
        //调用可变函数过滤数据
        $data = $v((string)$data);
    }
    return $data;
}
 
/**
 * JavaScript弹窗并返回
 */
function alert_back($msg){
    echo "<script>alert('$msg');history.back();</script>";
    exit;
}

主机名默认,用户名默认,密码填写数据库的密码,数据库名称写自己建立的database名称即可。

问题及解决方案 

我是搭建完成后才写这个的,可能有遗漏啥的qaq

1.数据库的使用

进入cmd,进入自己数据库的bin文件夹

执行命令 mysql -hlocalhost -uroot -p(搭建好的前提下)

若是没搭建好请看https://blog.csdn.net/qq_41307443/article/details/79839558  非常详细

问题一:MySQL登录时出现Access denied for user 'root'@'localhost' (using password: YES) 拒绝访问,并可修改MySQL密码

参考https://blog.csdn.net/qq_36675754/article/details/81381341

你在安装成功mysql后建表时会提醒你需要修改密码,这里折腾了我好长时间

博主赠一句

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
在你脑子混乱束手无策的时候这句有奇效!

当然cmd可能会提示你用户名重复,这时  Delete FROM user Where User='test' and Host='localhost';  

再重新创建并修改密即可。

问题二:Install/Remove of the Service Denied!

在c盘中用管理员身份打开cmd,再install mysql

问题三:php代码在网页上不能正确编译

打开Apache的httpd.conf配置文件,添加以下代码:

#加载PHP模块
LoadModule php5_module "D:/php-5.4.28/php5apache2_2.dll"
AddType application/x-httpd-php . php
PHPIniDir "D:/php-5.4.28"

地址记得改成自己的。

问题四:PHP环境搭建时缺少php7apache2_4.dll

回到上边第三点:没有dll文件是你下载了带有Non-Thread Safe的了,需要重新下载。

(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次

问题五:Fatal error: Failed opening required 

这个错误等同于 error: connect require()

这时候不要忙于检查你的init配置文件是否有错,而是在D:\搜狗高速下载\mysql-8.0.16-winx64\lib中找到libmysql.dll

并将其复制到C:\Windows\System32中,让系统识别这个文件。

-------------------------------------------------------------------------------------------------------

月光还是少年的月光,九州一色还是李白的霜

猜你喜欢

转载自www.cnblogs.com/jyn752430734/p/10927096.html