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. 基于nodejs的wiki系统

    jingo:        https://github.com/claudioc/jingo nodewiki:    https://github.com/nhoss2/nodewiki Tidd ...

  2. 模版抽离 优化url

    抽离出base模板 复制index的代码到base里面,指定views里面跳转到base.html,删除掉会变化的保留通用的 把主要内容写写在block里面,写了三个block {% block le ...

  3. mssql 中文乱码 字库集 问题解决方法

    The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法)   SQL S ...

  4. Hibernate一对多、多对一关联

    一对多.多对一关联:在多方加外键 示例:Group(一方)和User(多方),一个Group可以有多个User,每个User只能属于一个Group   多对一单向关联 在User(多方)中建Group ...

  5. 对象数组空指针异常说明——C#中使用对象数组必须分别为其开辟空间

    l  场景 定义一个学生类,包含字段(学号,姓名,语文成绩,数学成绩,英语成绩).属性(总成绩).三个方法分别为(求平均分.数学平均分.语文平均分). 要求:在main()方法中,定义一个学生类型的数 ...

  6. SpringBoot Redis工具类封装

    1.接口类 package com.sze.redis.util; import java.util.List; import java.util.Set; import java.util.conc ...

  7. DataTable Group By或运算 Linq Aggregate的使用

    class Program { static void Main(string[] args) { DataTable dt = new DataTable(); dt.Columns.Add(&qu ...

  8. problem-1003(恢复一下)

    问题: Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequenc ...

  9. 深入理解Node.js中的垃圾回收和内存泄漏的捕获

    深入理解Node.js中的垃圾回收和内存泄漏的捕获 文章来自:http://wwsun.github.io/posts/understanding-nodejs-gc.html Jan 5, 2016 ...

  10. Maven webapp index.jsp报错

    javax.servlet javax.servlet-api 3.1.0