最近遇到这样一个问题:
在网站中访问一个带参数的URL完全没有问题 --> like this index.php/crons/update_hot_level
这是常见的pathinfo访问模式
下面是我访问的update_hot_level方法中的代码
$this->load->database();
$this->db->select('*')->from('tables');
$query = $this->db->get();
var_dump($query);
输出结果如下:
object(mysqli)#27 (19) {
["affected_rows"]=>
NULL
["client_info"]=>
string(6) "5.5.54"
["client_version"]=>
int(50554)
["connect_errno"]=>
int(2002)
["connect_error"]=>
string(84) "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"
["errno"]=>
int(2002)
["error"]=>
string(84) "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"
}
然而费尽了一番周折,我找到了原因,跟网上搜到的原因都不一样
database.php 的文件中,hostname=‘localhost’
我将其改为 IP 地址即可访问,因为项目着急上线,原因还没有查出。
我想应该是地址与ip没有对应所以解析不到,才会报这种错误
此文档仅作为记录,之后查到原因后再做修改........
如果你也遇到这种错误,或已解决请留言, 谢谢!