Codeigniter出现A Database Error Occurred错误

下午把项目构建到服务器上的时候,codeigniter竟然出现了 a database error occurred 错误,以前在使用ci开发项目的时候没有遇到过这问题。

在本地测试虚拟机测试环境下没有出现问题,构建到生产环境后出现问题,觉得应该是系统配置问题。没有认真找其中的缘由,临时找了个方法解决了测试项目了。

1、更改入口文件 index.php 中的ENVIRONMENT 常量值

更改:
define('ENVIRONMENT', 'development');
为:
define('ENVIRONMENT', 'production');

临时屏蔽错误出现。

2、修改数据库配置项

修改:
$db['default']['db_debug'] = TRUE;
为:
$db['default']['db_debug'] = FALSE;

以上两步就可以解决Codeigniter出现A Database Error Occurred错误的问题,这只是治标的方法。

出现Unable to connect to your database server using the provided settings错误

问题的真正原因了:没有权限访问数据库。

错误提示:

Unable to connect to your database server using the provided settings

在找数据库链接问题的时候一直带着已经有权限访问的前提下去寻找答案,最后没辙了,又从源头开始找。

解决过程:

在config/database.php最后加上如下代码进行调试。

echo '<pre>';
print_r($db['default']);
echo '</pre>'; echo 'Trying to connect to database: ' .$db['default']['database'];
$dbh=mysql_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password'])
or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db['default']['database']); echo '<br /> Connected OK:' ;
die( 'file: ' .__FILE__ . '--> Line: ' .__LINE__);

重新访问网站,提示服务器没有权限访问数据库,又屁颠屁颠地去设置了访问权限后,一切OK。

通过这件事,得到教训:别人说的,有时未必完全是正确的,验证了那句话“眼见为实”。

codeigniter教程:Codeigniter出现Unable to connect to your databas的更多相关文章

  1. chrome的uget扩展程序红色 Unable to connect with uget-integrator问题

    我们根据网上的教程在ubuntu16.04中安装下载工具uget+aria2并配置chrome时,最后重新打开chrome浏览器,发现uget扩展程序是红色的,点开看到”Unable to conne ...

  2. telnet报“Unable to connect to remote host:Connection refused”错误

    Linux下面telnet ip 端口号 报错误"Unable to connect to remote host:Connection refused"的时候,大部分是目标机的端 ...

  3. svn检出的时候报 Unable to connect to a repository at URL错误(摘自CSDN)

    背景:1.         SVN服务器:VisualSVN-Server-2.5.5: 2. SVN客户端:TortoiseSVN-1.7.6.22632-x64-svn-1.7.4.msi: 在S ...

  4. Error: unable to connect to node rabbit@mail: nodedown

    某天,开启一个应用时,发现连接rabbitmq失败,本来想用rabbitmqctl来查看队列,结果提示“Error: unable to connect to node rabbit@mail: no ...

  5. SVN Unable to connect to a repository at UR

    背景: 1.         SVN服务器:VisualSVN-Server-2.5.5: 2.         SVN客户端:TortoiseSVN-1.7.6.22632-x64-svn-1.7. ...

  6. RabbitMQ安装后不能运行 Error: unable to connect to node nodedown

    本地安装RabbitMQ后总是不能正常的使用.. 命令行输入 rabbitMQctl Status  报下边的错 Error: unable to connect to node 'rabbit@YO ...

  7. start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart:

    用Ubuntu远程登录虚拟host时出现:    start: Unable to connect to Upstart: Failed to connect to socket /com/ubunt ...

  8. Selenium2学习-038-firefox、webdriver版本不对称问题解决:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055

    今天有个朋友在群里问,为何脚本运行不通过,其脚本操作步骤简单描述如下: 1.启动火狐浏览器 2.打开百度 3.查询框输入关键字 4.点击按钮[百度一下] 脚本挺简单的,其给出的应用报错信息如下所示: ...

  9. svn更新报错:svn unable to connect to a repository at url

    出现错误:unable to connect to a repository at url 解决办法1. 右键点击本地副本,TortoiseSVN -> Settings -> Saved ...

随机推荐

  1. corethink功能模块探索开发(三)让这个模块可见

    感觉corethink把thinkphp的思想复用到淋漓尽致. 1.把opencmf.php文件配置好了后台该模块的菜单就能在安装后自动读取(分析好父子关系,否则页面死循环,apache资源占用率10 ...

  2. CSRF(Cross Site Request Forgery, 跨站请求伪造)

    一.CSRF 背景与介绍 CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,它在 2007 年曾被列为互联网 20 大安全隐患之一.其他安全隐患, ...

  3. python调用php函数

    由于php不支持多线程,所以想借助python搞一个.1.import subprocessimport time#Simple caller, disguard outputmethod=" ...

  4. iOS Xcode 8 快捷键 (注释 失效 处理)

    在升级后,好用的VVDocumment 插件不能用了.(但是苹果这次内置了好多好用的插件,也有自己的注释功能了 AddDocumentation) 上网上有查到 传播很广泛的一条信息 "这个 ...

  5. cocos打包出现错误,执行命令出错,返回值:2。 Traceback (most recent call last): File "E:\cocos_workspace\MyGameOne\proj.android\build_native.py", line 43, in <module> build(opts.build_mode) File "E:\cocos_workspace\MyGa

    先看看NDK的版本,如果不行,就删除\proj.android\obj\local\armeabi下的文件.

  6. 防止iframe被别的网站引用

    try{ top.location.hostname; if (top.location.hostname != window.location.hostname) { top.location.hr ...

  7. string 类(二)

    处理string对象中的字符: 在cctype头文件中定义了一组标准库函数来处理string对象中的字符,比如检查一个string对象是否包含空白,或者把string对象中的字母改成小写,再或者查看某 ...

  8. Linux下检测IP访问特定网站的ruby脚本

    root@ubuntu:~# vi check_ip.rbrequire 'rubygems' index = 1 max = 20 while (max-index) >= 0 puts in ...

  9. ssm搭建相关的问题

    在搭建ssm框架时候踩得坑:1.对于拦截器url-parttern的设置:第一次设置的是/** 本以为这个是表示拦截所有,没想到这是错误的写法,正确的写法是/    启动项目不会报错,但是会出现404 ...

  10. dfs枚举

    深度优先搜索(DFS,Depth-First Search)是搜索手段之一.它从某个状态开始,不断的转移状态知道无法转移,然后退回到前一步的状态,继续转移到其他状态,如此不断重复,直到找到最终的解. ...