CodeIgniter:无法使用提供的设置连接到您的数据库服务器错误消息 [英] CodeIgniter: Unable to connect to your database server using the provided settings Error Message

查看:26
本文介绍了CodeIgniter:无法使用提供的设置连接到您的数据库服务器错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用 MySQL 驱动程序很好地使用 CI.我想改用 MySQL 驱动程序,但是一旦我更改它(只需在 MySQL 末尾添加i",并添加端口号),我就会收到以下错误消息

I have been using CI just fine using the MySQL driver. I want to use the MySQL driver instead, but as soon as I change it (just add the ‘i’ at the end of MySQL, and added the port number) I get the following error message

发生数据库错误

无法使用提供的设置连接到您的数据库服务器.

Unable to connect to your database server using the provided settings.

文件名:core/Loader.php

Filename: core/Loader.php

行号:232

我的设置如下:

$db['default']['hostname'] = $hostname;
$db['default']['username'] = $username;
$db['default']['password'] = $password;
$db['default']['database'] = $database;
$db['default']['dbdriver'] = 'mysqli';
$db['default']['port']     = "3306";  
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE; 

where
$hostname = 'localhost';
$username = 'myusernamegoeshere';
$password = 'mypasswordgoeshere';
$database = 'mydatabasenamegoeshere'; 

我正在使用:

CI 2.0.2 php 5.3.4 Apache/2.2.17 (Unix) mysql 5.5.13 mysql.default_port 3306

CI 2.0.2 php 5.3.4 Apache/2.2.17 (Unix) mysql 5.5.13 mysql.default_port 3306

我做错了什么吗?

谢谢,

推荐答案

对我来说,问题出在 php.ini 文件中.属性 mysql.default_socket 指向不存在目录中的文件.该属性指向 /var/mysql/mysql.sock 但在 OSX 中,该文件位于 /tmp/mysql.sock.

For me the issue was in the php.ini file. The property mysql.default_socket was pointing to file in a non-existent directory. The property was pointing to /var/mysql/mysql.sock but in OSX, the file was located in /tmp/mysql.sock.

一旦我更新了 php.ini 中的条目并重新启动了网络服务器,问题就解决了.

Once I updated the entry in php.ini and restarted the webserver, the issue was resolved.

这篇关于CodeIgniter:无法使用提供的设置连接到您的数据库服务器错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆