如何使用 CodeIgniter 测试数据库连接?
我正在尝试学习 CodeIgniter,但不幸的是,他们在 wiki 上列出的许多教程已有几年历史,并且根据其他人的评论,不适用于最新版本的 CodeIgniter。
我确实找到了一个没有任何负面评论的 - IBM DeveloperWorks - 但我无法让它工作。表单提交之前的一切都很好,但是提交后我得到一个空白页面,并且没有任何内容发送到数据库。
如何在 CodeIgniter 中测试/排除数据库连接故障?我知道我的设置(就主机、数据库名、用户名/密码等而言)是正确的,因为我在普通的 PHP 站点上成功使用了它们。
编辑添加:或者,任何人都可以向我指出适用于最新版本的最新初学者教程吗?我不需要 MVC 教程;我需要的是 MVC 教程。我熟悉设计模式。我只需要学习CodeIgniter。
编辑以添加database.php文件:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$active_group = "default";
$active_record = TRUE;
//$db['default']['hostname'] = "localhost";
$db['default']'hostname'] = "myHostName.powwebmysql.com";
$db['default']['username'] = "myUserName";
$db['default']['password'] = "myPassword";
$db['default']['database'] = "codeigniter"; //yes, database is called codeigniter
$db['default']['dbdriver'] = "mysql";
$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";
/* End of file database.php */
/* Location: ./system/application/config/database.php */
编辑:将数据库加载添加到构造函数时出现错误消息:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$load
Filename: controllers/welcome.php
Line Number: 6
其中第6行是$this->load->database();
I'm trying to learn CodeIgniter, but unfortunately many of the tutorials they list on their wiki are several years old and, based on others' comments, don't work on the newest version of CodeIgniter.
I did find one that didn't have any negative comments - on IBM DeveloperWorks- but I can't get it to work. Everything up until the form submit is fine, but after I submit I get a blank page and nothing is sent to the database.
How can I test/troubleshoot a database connection in CodeIgniter? I know my settings (as far as host, dbname, username/password, etc.) are correct because I'm using them successfully with a plain vanilla PHP site.
Edit to add: alternatively, can anyone point me to a recent beginner tutorial that works with the recent version? I don't need an MVC tutorial; I'm familiar with the design pattern. I just need to learn CodeIgniter.
Edit to add database.php file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$active_group = "default";
$active_record = TRUE;
//$db['default']['hostname'] = "localhost";
$db['default']'hostname'] = "myHostName.powwebmysql.com";
$db['default']['username'] = "myUserName";
$db['default']['password'] = "myPassword";
$db['default']['database'] = "codeigniter"; //yes, database is called codeigniter
$db['default']['dbdriver'] = "mysql";
$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";
/* End of file database.php */
/* Location: ./system/application/config/database.php */
EDIT: error message when adding database load to constructor:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$load
Filename: controllers/welcome.php
Line Number: 6
where line 6 is $this->load->database();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是一些最新的 codeigniter 初学者教程:
我喜欢 Jeffrey Way 系列视频系列。
http://net.tutsplus.com/articles/news/ codeigniter-from-scratch-day-1/
http://net.tutsplus.com/articles/news/ codeigniter-from-scratch-day-2/
http://net.tutsplus.com/articles/news/ codeigniter-from-scratch-day-3/
http://net.tutsplus.com/articles/新闻/codeigniter-from-scratch-day-4-newsletter-signup/
http://net.tutsplus.com/articles/新闻/codeigniter-from-scratch-day-5-crud/
Here are some more recent beginner tutorial for codeigniter:
I enjoy the Jeffrey Way series video series.
http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-1/
http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-2/
http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-3/
http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-4-newsletter-signup/
http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-5-crud/
请使用下面的代码:
Please use below code: