2013-10-11 3 views
7

निर्दिष्ट किया है मैं एक ट्यूटोरियल से एक CRUD बना रहा हूँ। और मुझे यह त्रुटि मिल रही है।आपने एक अवैध डेटाबेस कनेक्शन समूह कोडigniter त्रुटि

आपने एक अवैध डेटाबेस कनेक्शन समूह निर्दिष्ट किया है।

समस्या क्या होगी?

database.php - डेटाबेस config

$db['default']['hostname'] = 'localhost'; 
$db['default']['username'] = 'root'; 
$db['default']['password'] = ''; 
$db['default']['database'] = 'cicrud'; 
$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'; 
$db['default']['swap_pre'] = ''; 
$db['default']['autoinit'] = TRUE; 
$db['default']['stricton'] = FALSE; 

users_model.php -model

<?php 

class Users_model extends CI_Model { 

function __construct() 

{ 

parent::__construct(); 

$this->load->database('cicrud'); 

} 

public function get_all_users() 

{ 

$query = $this->db->get('users'); 

return $query->result(); 

} 
public function insert_users_to_db($data) 

{ 

return $this->db->insert('users', $data); 

} 

} 

?> 

users.php - नियंत्रक

<?php 

if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Users extends CI_Controller { 

function __construct() 

{ 

parent::__construct(); 

#$this->load->helper('url'); 

$this->load->model('users_model'); 

} 

public function index() 

{ 

$data['user_list'] = $this->users_model->get_all_users(); 

$this->load->view('show_users', $data); 

} 
public function add_form() 

{ 

$this->load->view('insert'); 

} 
public function insert_new_user() 

{ 

$udata['name'] = $this->input->post('name'); 

$udata['email'] = $this->input->post('email'); 

$udata['address'] = $this->input->post('address'); 

$udata['mobile'] = $this->input->post('mobile'); 

$res = $this->users_model->insert_users_to_db($udata); 

if($res){ 

header('location:'.base_url()."index.php/users/".$this->index()); 

} 

} 
} 

show_users.php - एचटीएमएल विचार

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

<title>CI CRUD</title> 

<script type="text/javascript"> 

function show_confirm(act,gotoid) 

{ 

if(act=="edit") 

var r=confirm("Do you really want to edit?"); 

else 

var r=confirm("Do you really want to delete?"); 

if (r==true) 

{ 

window.location="<?php echo base_url();?>index.php/users/"+act+"/"+gotoid; 

} 

} 

</script> 

</head> 

<body> 

<h2> Simple CI CRUD Application </h2> 

<table width="600" border="1" cellpadding="5"> 

<tr> 

<th scope="col">Id</th> 

<th scope="col">User Name</th> 

<th scope="col">Email</th> 

<th scope="col">Mobile</th> 

<th scope="col">Address</th> 

<th scope="col" colspan="2">Action</th> 

</tr> 

<?php foreach ($user_list as $u_key){ ?> 

<tr> 

<td><?php echo $u_key->id; ?></td> 

<td><?php echo $u_key->name; ?></td> 

<td><?php echo $u_key->email; ?></td> 

<td><?php echo $u_key->address; ?></td> 

<td><?php echo $u_key->mobile; ?></td> 

<td width="40" align="left" ><a href="#" onClick="show_confirm('edit',<?php echo $u_key->id;?>)">Edit</a></td> 

<td width="40" align="left" ><a href="#" onClick="show_confirm('delete',<?php echo $u_key->id;?>)">Delete </a></td> 

</tr> 

<?php }?> 

<tr> 

<td colspan="7" align="right"> <a href="<?php echo base_url();?>index.php/user/add_form">Insert New User</a></td> 

</tr> 

</table> 

</body> 

</html> 

उत्तर

16

आप लोड कर रहे हैं एक डेटाबेस समूह circrud कहा जाता है। लेकिन उसमें कोई डेटाबेस समूह नहीं है। आपके पास केवल एक ही समूह है जिसे default कहा जाता है जिसे डिफ़ॉल्ट रूप से लोड किया जाएगा यदि आप समूह निर्दिष्ट नहीं करते हैं।

$this->load->database('cicrud');

तुम बस कोड के इस हिस्से में

$this->load->database(); करना चाहिए: अपने डेटाबेस कनेक्शन में

class Users_model extends CI_Model { 

function __construct() 

{ 

parent::__construct(); 

$this->load->database(); 

} 
+0

धन्यवाद !!! यह काम किया :) – Beabi

+0

धन्यवाद borther ... –

+0

धन्यवाद। अब यह काम कर रहा है :) –

4

आप पहले से ही डेटाबेस समूह उपयोग कर रहे हैं "cicrud" यहाँ:

$this->load->database('cicrud'); 

तो आप इसे बदल सकते हैं:

$this->load->database(); 

या आप इस के लिए अपने config बदल सकते हैं:

$db['cicrud']['hostname'] = 'localhost'; 
$db['cicrud']['username'] = 'root'; 
$db['cicrud']['password'] = ''; 
$db['cicrud']['database'] = 'cicrud'; 
$db['cicrud']['dbdriver'] = 'mysql'; 
$db['cicrud']['dbprefix'] = ''; 
$db['cicrud']['pconnect'] = TRUE; 
$db['cicrud']['db_debug'] = TRUE; 
$db['cicrud']['cache_on'] = FALSE; 
$db['cicrud']['cachedir'] = ''; 
$db['cicrud']['char_set'] = 'utf8'; 
$db['cicrud']['dbcollat'] = 'utf8_general_ci'; 
$db['cicrud']['swap_pre'] = ''; 
$db['cicrud']['autoinit'] = TRUE; 
$db['cicrud']['stricton'] = FALSE; 

देखें कि आप के लिए बेहतर है।

संबंधित मुद्दे