Centos7环境-php7-MariaDB5.5.60

(新安装的php7,执行php -m 显示有mysqli模块,php.ini没有改其它)

测试代码为:

<?php
//~ echo date('Y-m-d H:i:s',time());
$link_id = mysqli_connect('localhost','root','');
if($link_id)
{
echo 'ok';
}
else
{
echo mysqli_connect_error();
}
?>

网页运行时显示 No such file or directory 错误

把参数 'localhost' 换成 ‘127.0.0.1’ 后 显示 ok,即执行成功!如果想使用 ‘localhost' 这个参数

如果是新安装的MariaDB,一定要先执行

mysql_secure_installation

根据提示安装完成之后,再运行上述代码正常情况下就运行成功了。如果还显示错误再参考下面

解决方法为:

  找到 /etc/my.cnf 文件(我的是在这个位置,具体根据自己的机器)

  找到这一行:

  

  然后找到 /etc/php.ini

  找到这一行:

  

  默认情况下为空,把它修改为上述路径就可以了(不用加引号)

  重新启动php-fpm

  使用 ’localhost' 参数,刷新网页显示 'ok',即运行成功

参考:【故障】php链接mysql数据库,使用localhost一直显示错误,当使用127.0.0.1l链接正常,故障记录

php的mysqli_connect函数显示 No such file or directory错误以及localhost换成127.0.0.1执行成功的更多相关文章

  1. php 连接mysql 主机 localhost,显示 No such file or directory

    打开 php.ini文件,找到这1行 mysql.default_socket 然后将它修改为 mysql.default_socket=/path/to/mysql.sock /path/to/my ...

  2. /etc/rc.d/init.d/iptables: No such file or directory 错误原因

    注:本文转载自cnblogs:一天学点的文章</etc/rc.d/init.d/iptables: No such file or directory 错误原因> RedHat Enter ...

  3. mkdir()提示No such file or directory错误的解决方法

    转自:http://www.02405.com/program/php/1692.html 在php中使用mkdir()方法创建文件夹时报错:No such file or directory,出错代 ...

  4. Linux运行shell脚本提示No such file or directory错误的解决办法

    Linux执行.sh文件,提示No such file or directory的问题: 原因:在windows中写好shell脚本测试正常,但是上传到 Linux 上以脚本方式运行命令时提示No s ...

  5. python打包成.exe工具py2exe0-----No such file or directory错误

    转自:http://justcoding.iteye.com/blog/900993 一.简介 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具, ...

  6. 执行Python "/bin/usr/python: bad interpreter: No such file or directory" 错误

    今天在电脑上写了一个Python脚本,写好之后用ftp传上去,然后执行/var/www/cron.py,结果报错,/bin/usr/python: bad interpreter: No such f ...

  7. Mysql_connect报告”No such file or directory”错误的解决方法

    写了个php脚本单独执行mysql_connect(),发现错误信息居然是“No such file or directory"! 首先确定是mysql_connect()和mysql_pc ...

  8. find: `./folder': No such file or directory 错误处理

    这是我正在处理的目录的内容: misha@hp-laptop:~/work/c/5$ ls -l total 8 -rw-rw-r-- 1 misha misha 219 May 20 15:37 d ...

  9. 解决openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory错误

    问题 在Centos7上编译安装openssl后,运行openssl version出现如下错误: openssl: error while loading shared libraries: lib ...

随机推荐

  1. MyEclipse 2017/2018 安装与破解 图文教程

    SSM 框架-02-MyEclipse 2017/2018 安装与破解 现在在学J2EE,然后使用的工具就是 MyEclipse,现在就抛弃 Eclipse 了,我就不多说它俩的区别了,但是 MyEc ...

  2. AndroidStudio中logcat不输出信息

    2017年11月27日,记住这个日子.今天第一次感觉到被批评了,由于自己技术知识储备不足导致今天的外出工作等于浪费时间.正式因为这个logcat不输出信息的问题,前几回不输出信息了我就从新启动了开发工 ...

  3. Mysql rpm安装

    总结下mysql rpm安装的方式,与一些错误 环境[root@host2 ~]# uname -aLinux host2 2.6.32-504.3.3.el6.x86_64 #1 SMP Wed D ...

  4. 基于bootstrap模态框的alert弹窗

    完成的效果如下: html代码: <!-- 弹出框 --> <div class="modal fade" id="alert_like" t ...

  5. hmac 算法模块

    Hmac算法:Keyed-Hashing for Message Authentication.它通过一个标准算法,在计算哈希的过程中,把key混入计算过程中 Python自带的hmac模块实现了标准 ...

  6. npm WARN network …… request to https://cnpmjs.…… failed, reason: socket hang up

    出现类似问题的原因是由于之前配置了镜像导致的 解决方案:删掉镜像,使用npm本身进行安装 删除镜像的命令: 方法1: npm config delete registry 方法2: npm confi ...

  7. Scala高阶函数

    1.作为参数的函数 函数可以作为一个参数传入到一个方法当中去 def main(args: Array[String]): Unit = { val myFunc1 =(x:Int) =>{ x ...

  8. 彻底关闭Firefox自动更新的方法

    自己最近在使用firefox进行自动化测试时,发现配置好的firefox总是会自动更新,主要是因为一些高版本的浏览器无法安装firepath,没有firepath的火狐浏览器使用起来总是有很多的不方便 ...

  9. linux性能系列--网络

    一.为啥网络监控不好做?   回答:网络是所有子系统中最难监控的了.首先是由于网络是抽象的,更重要的是许多影响网络的因素并不在我们的控制范围之内.这些因素包括,延迟.冲突.阻塞等 等.由于网络监控中, ...

  10. 1、关于python第三方工具操作xls和xlsx格式的excel文档选型的吐血经历

    首先,最近看了python的一本书,其中第7章是关于文章操作的,就计划把python操作excel,word,txt,xml,html,json等格式的文档做个总结,并实现一些功能,但是,第一步就要把 ...