YII 错误 SQLSTATE[HY000] [2002] No such file or directory
在使用yii的yii\db\Connnection时发生错误
<?php
namespace app\controllers; use yii\web\Controller;
use yii\db\Connection;
use Yii; class MyController extends Controller
{
public function actionIndex()
{
$country = Yii::$app -> db -> createCommand("select * from country") -> queryAll();
print_r($country);
}
}
错误:

解决方法:将config目录下的db.php配置文件中的localhost改为127.0.0.1即可
<?php return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii',
'username' => 'root',
'password' => '12',
'charset' => 'utf8',
];
当主机填写为localhost时mysql会采用 unix domain socket连接
当主机填写为127.0.0.1时mysql会采用tcp方式连接
这是linux套接字网络的特性,win平台不会有这个问题
YII 错误 SQLSTATE[HY000] [2002] No such file or directory的更多相关文章
- Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory解决方法
今天用pdo连接mysql遇到一个奇怪的问题,host设为127.0.0.1可以连接成功,设为localhost就会报如下的错误: PHP Fatal error: Uncaught excepti ...
- [PDOException] SQLSTATE[HY000] [2002] No such file or directory
编译安装PHP7之后,在安装mysql之后,用pdo操作数据库的时候,出现了此错误[PDOException] SQLSTATE[HY000] [2002] No such file or direc ...
- TP连接数据库报错:SQLSTATE[HY000] [2002] No such file or directory
连接数据库报错:“SQLSTATE[HY000] [2002] No such file or directory”. 出现这个问题的原因是PDO无法找到mysql.sock或者mysqld.soc ...
- laravel 报错SQLSTATE[HY000] [2002] No such file or directory
在mac中执行php artisan migrate时报错 SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from i ...
- Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory
执行下面的代码报错: $pdo = new PDO('mysql:dbname=db_test;host=localhost', 'root', '123456'); PHP Fatal error: ...
- PHP连接MySQL的时候报错SQLSTATE[HY000] [2002] No such file or directory
错误环境:Mac OS 10.10 找到mysql.sock文件的位置 $sudo find / -name mysql.sock ------结果如下---------- find: /dev/fd ...
- SQLSTATE[HY000] [2002] No such file or directory in
这个错误将数据库配置信息的localhost改成127.0.0.1就行了
- Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory'
1.根本原因在http://askubuntu.com/questions/606732/php-fatal-error-uncaught-exception-pdoexception-with-me ...
- 【不积跬步,无以致千里】安装roundcube 时出现 “DSN (write): NOT OK(SQLSTATE[HY000] [2002] No such file or directory)”
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
随机推荐
- JS 阶段练习~ 仿flash的图片轮换效果
结合了所学的简单运动框架~ 做这样一个综合小实例~~ -------------------------主要问题: 1.getByClassName IE低版的兼容性 2.DOM不够严谨 … 各种 ...
- 又见SpringMVC
一.如何让一个普通类成为Controller? 方案一:实现接口Controller解析:handleRequest(request,response) 方案二:继承AbstractControlle ...
- linux的学习记录随笔
为什么学习linux 因为操作系统是一种介质,你要接触其中的东西,首先必须要有介质,而linux在服务器端是老大哥的地位,所以呢,学习linux吧. 学习的方式 可以看视频 imooc.百度传课.网易 ...
- MongoDB查询转对象是出错Element '_id' does not match any field or property of class
MongoDB查询转对象是出错Element '_id' does not match any field or property of class 解决方法: 1.在实体类加:[BsonIgno ...
- python优先队列,队列和栈
打印列表的疑问 class Node: def __str__(self): return "haha" print([Node(),Node()]) print(Node()) ...
- ActiveMQ在Linux中的安装
1.下载相关activeMQ安装包 下载路径:http://activemq.apache.org/download.html 下载最新安装包,选择Linux版进行下载 2.解压重命名 (1)解压: ...
- [转]使用Enumeration和Iterator遍历集合类
原文地址:http://www.cnblogs.com/xwdreamer/archive/2012/05/30/2526268.html 前言 在数据库连接池分析的代码实例中,看到其中使用Enume ...
- CentOS 6/7安装ffmpeg
环境 CentOS 6/7 安装 导入GPG key rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms 安装ATRPMS Repo ...
- 文档分享-Activiti 5.16 用户手册
今天在翻看工作流相关的网页的时候,在开源中国上http://www.oschina.net/question/915507_149175发现activiti的中文文档:http://www.mossl ...
- U盘存放大于4G数据文件且无须格式化U盘的解决方法
现在优盘的容量越来越大了,价格越来越便宜,可是它也有个缺点,因为它默认的文件系统是"FAT32",这种文件系统最大只能保存4G的文件,超过4G的文件就不能保存在优盘上了,这样就不能 ...