开发者

How can I test a database connection with CodeIgniter?

开发者 https://www.devze.com 2023-01-29 06:53 出处:网络
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 CodeIgnite

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开发者_StackOverflow 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();


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:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'myUserName';
$db['default']['password'] = 'myPassword';
$db['default']['database'] = 'myDatabaseName';


/** Do not change the below values. Change only if you know what you are doing */
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = "utf8"; 
$db['default']['dbcollat'] = "utf8_unicode_ci";
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$active_group = 'default';
$active_record = TRUE;
0

精彩评论

暂无评论...
验证码 换一张
取 消