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 ...
随机推荐
- 解决You are using pip version 9.0.1, however version 9.0.3 is available. You should consider upgra
直接运行命令:python -m pip install --upgrade pip
- Java并发—线程常用方法总结
1.join()方法 join —— 让一个线程等待另一个线程完成才继续执行.如A线程线程执行体中调用B线程的join()方法,则A线程被阻塞,知道B线程执行完为止,A才能得以继续执行. public ...
- ansible的主机变量
ansible的主机变量(常用):ansible_ssh_host #用于指定被管理的主机的真实IPansible_ssh_port #用于指定连接到被管理主机的ssh端口号,默认是2 ...
- Python traps and pitfalls
@1: >>> def func(a, L=[]): ... L.append(a) ... print(L) ... >>> func(10) [10] > ...
- Python Variable Scope
Python中的变量的作用域有时会让像我这样的初学者很头疼. 其实只需要掌握以下两点: 1. Python能够改变变量作用域的代码段是def.class.lamda; 而if/elif/else ...
- spring mvc 自动扫描注解失效原因
关于spring自动扫描,在控制层,采用注解配置@Controller,项目能够成功启动,且无任何报错.但是 在进行页面跳转时,并未进行相应的拦截,整个界面只能在默认界面 ,跳转报404,由于楼主初次 ...
- 17 南宁区域赛 F - The Chosen One 【规律】
题目链接 https://nanti.jisuanke.com/t/19972 题意 给出一个n 然后将 n 个数 标号为 1 -> n 按顺序排列 每次抽掉 奇数位的数 然后求最后剩下那个数字 ...
- Kafka Confluent
今天我们要讲的大数据公司叫作Confluent,这个公司是前LinkedIn员工出来后联合创办的,而创业的基础是一款叫作Apache Kafka的开源软件. Confluen联合创始人Jun Rao即 ...
- JSP DAO(Model)
示例代码: 1. Users类 package com.po; public class Users { private String username; private String passwor ...
- vector对象
vector是模板而非类型,由vector生成的类型必须包含vector中元素的类型,例如vector<int> 定义和初始化vector对象: vector<T> v1 ...