codeigniter教程:Codeigniter出现Unable to connect to your databas
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的更多相关文章
- chrome的uget扩展程序红色 Unable to connect with uget-integrator问题
我们根据网上的教程在ubuntu16.04中安装下载工具uget+aria2并配置chrome时,最后重新打开chrome浏览器,发现uget扩展程序是红色的,点开看到”Unable to conne ...
- telnet报“Unable to connect to remote host:Connection refused”错误
Linux下面telnet ip 端口号 报错误"Unable to connect to remote host:Connection refused"的时候,大部分是目标机的端 ...
- 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 ...
- Error: unable to connect to node rabbit@mail: nodedown
某天,开启一个应用时,发现连接rabbitmq失败,本来想用rabbitmqctl来查看队列,结果提示“Error: unable to connect to node rabbit@mail: no ...
- 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. ...
- RabbitMQ安装后不能运行 Error: unable to connect to node nodedown
本地安装RabbitMQ后总是不能正常的使用.. 命令行输入 rabbitMQctl Status 报下边的错 Error: unable to connect to node 'rabbit@YO ...
- 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 ...
- 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.点击按钮[百度一下] 脚本挺简单的,其给出的应用报错信息如下所示: ...
- svn更新报错:svn unable to connect to a repository at url
出现错误:unable to connect to a repository at url 解决办法1. 右键点击本地副本,TortoiseSVN -> Settings -> Saved ...
随机推荐
- Java技术相关
1.System.getProperty("user.dir") References:API
- php异常处理类
<?php header('content-type:text/html;charset=UTF-8'); // 创建email异常处理类 class emailException extend ...
- loadrunder之脚本篇——定义全局变量
如果参数是全局的,在脚本中的任何一个Action中都可以使用,变量一般是局部的,如果跨Action调用会出现未声明的错误. 打开Script视图中左侧Action列表中的globals.h文件,可定义 ...
- PHP汉子转拼音
<?php /** +------------------------------------------------------ * PHP 汉字转拼音 +------------------ ...
- php数组函数-array_rand()
array_rand()函数返回数组中的一个随机键名,或者如果指定函数返回键名不止一个,则返 回一个包含随机键名的数组. array_rand(array,number); array:必需.规定数组 ...
- 大话设计模式之PHP篇 - 策略模式
什么是策略模式? 定义:策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变化. 组成:抽象策略角色: 策略类,通常由一个接口或者抽象 ...
- INSPIRED启示录 读书笔记 - 第6章 招聘产品经理
产品经理应有的特质 个人素质和态度:技术可以学习,素质却难以培养,有些素质是成功的产品经理必不可少的 对产品的热情:对产品有一种本能的热爱,是夜以继日克服困难.完善产品的动力 用户立场:能换位思考,能 ...
- Android系统--Binder系统具体框架分析(一)补充
Android系统--Binder系统具体框架分析(一)补充 补充:对Binder驱动分析一的代码补充,添加saygoobye和saygoodbye_to服务 test_server.h #ifnde ...
- Introduction to vSphere Integrated Containers
vSphere Integrated Containers enables IT teams to seamlessly run traditional workloads and container ...
- 微服务(MicroServices)
微服务Architecture(MicroServices) 微服务架构简单的定义 采用一组Service的方式来构建一个应用,服务独立部署在不同的进程(Container)中,不同Service通过 ...