php – 您指定了无效的数据库连接组codeigniter错误

前端之家收集整理的这篇文章主要介绍了php – 您指定了无效的数据库连接组codeigniter错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在从教程中制作一个CRUD.我收到了这个错误.

You have specified an invalid database connection group.

会出现什么问题?

database.PHP数据库配置

$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 – html视图

<!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>
您正在加载名为circrud的数据库组.但是没有数据库组称之为.您拥有的唯一一个名为default的组,如果您未指定组,则默认情况下将加载该组.

$这 – >负载>数据库( ‘cicrud’);

你应该这样做

$这 – >负载>数据库();在这部分代码中:

class Users_model extends CI_Model {

function __construct()

{

parent::__construct();

$this->load->database();

}
原文链接:https://www.f2er.com/php/135291.html

猜你在找的PHP相关文章