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

编程入门 行业动态 更新时间:2024-10-04 11:23:22
本文介绍了您指定了无效的数据库连接组codeigniter错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我从教程制作CRUD。

您指定了无效的数据库连接组。

会有什么问题?

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-&用户',$ data); } } ?>

users.php - 控制器

<?php if(!defined('BASEPATH'))exit('不允许直接脚本访问); 类用户扩展CI_Controller { 函数__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-& > 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-& ); } } }

show_users.php - html视图

<!DOCTYPE html PUBLIC // DTD XHTML 1.0 Transitional // ENwww.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> < html xmlns =www.w3/1999/xhtml> < head> < meta http-equiv =Content-Typecontent =text / html; charset = utf-8/> < title> CI CRUD< / title> < script type =text / javascript> function show_confirm(act,gotoid) { if(act ==edit) r = confirm(你真的要编辑吗?); else var r = confirm(你真的要删除吗? if(r == true) { window.location =<?php echo base_url();?> index .php / users /+ act +/+ gotoid; } } < / script> < / head> < body> < h2>简单CI CRUD应用程序< / h2> < table width =600border =1cellpadding =5> < tr> < th scope =col> Id< / th> < th scope =col>用户名< / th> < th scope =col>电子邮件< / th> < th scope =col> Mobile< / th> < th scope =col>地址< / th> < th scope =colcolspan =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 =40align =left>< a href =#onClick =show_confirm('edit',<?php echo $ u_key-> id>?>)> Edit< / a>< / td> < td width =40align =left>< a href =#onClick =show_confirm('delete',<?php echo $ u_key-& id;?>)> Delete< / a>< / td> < / tr> <?php}?> < tr> < td colspan =7align =right> < a href =<?php echo base_url();?> index.php / user / add_form>插入新用户< / a>< / td> < / tr> < / table> < / body> < / html>

解决方案

正在加载一个名为 circrud 。但是没有数据库组称之为。您唯一拥有的是一个名为 default 的组,如果您未指定组,将默认加载

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

do

$ this-> load-> database(); / p>

class Users_model extends CI_Model { function __construct() { parent :: __ construct(); $ this-> load-> database(); }

i'm making a CRUD from a tutorial. And i'm getting this error.

You have specified an invalid database connection group.

What would be the problem?

database.php - database 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 - controller

<?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 views

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3/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>

解决方案

You are loading a database group called circrud. But there are no database group called that. The only one you have is a group called default which will be loaded by default if you don't specify a group.

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

You should just do

$this->load->database(); in this part of the code:

class Users_model extends CI_Model { function __construct() { parent::__construct(); $this->load->database(); }

更多推荐

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

本文发布于:2023-11-02 06:45:06,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库连接   错误   codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!