【问题标题】:codeigniter database error addcodeigniter 数据库错误添加
【发布时间】:2017-02-17 20:04:15
【问题描述】:

发生数据库错误

错误号:1146

表 'gtv.1tbpost' 不存在

插入1tbpost (post_title) 值 ('')

文件名:C:/xampp/htdocs/1/system/database/DB_driver.php

行号:691


数据库.php /

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'gtv',
    'dbdriver' => 'mysqli',
    'dbprefix' => '1',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

型号:

public function add(){
            $data=array(

            'post_title'=>$this->input->post('title'),

            );
        $this->db->insert('tbpost',$data);
        }

控制者:

   public function add_validate(){
        $this->load->library('form_validation');

        $this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[6]|regex_match[/^[A-Za-z0-9 .]+$/]');
        $this->form_validation->set_rules('image', 'Image', 'trim');
        $this->form_validation->set_rules('text', 'Text', 'trim|required|min_length[2]');

        $this->form_validation->set_message('required', '%s is required.');
        $this->form_validation->set_message('min_length', 'minimum characters for %s is %s');
        $this->form_validation->set_message('regex_match', '%s is not in the correct format');

        if($this->form_validation->run() == FALSE){
            if($this->input->post('add') == "post"){
                $this->gtvmod->add();
            }else if($this->input->post('add') == "save"){
                $this->index();
            }else if($this->input->post('add') == "cancel"){
                $this->index();
            }else{
                $this->index();
            }

        }else{
            if($this->input->post('add') == "post"){
                $this->add();//punta model
            }else if($this->input->post('add') == "save"){
                $this->index();//punta model
            }else if($this->input->post('add') == "cancel"){
                $this->index();//punta model
            }else{
                $this->index();//punta model
            }
        }
    }

问题我指定我的表是 'tbpost' 但错误说我插入到表 '1tbpost' 中。

【问题讨论】:

  • 您是否在应用程序的其他地方进行了其他成功的插入?
  • @charlietfl 我刚刚开始使用 codeigniter
  • 很好...只是好奇您是否有任何其他数据库插入工作或选择甚至为此。某处配置错误……但不确定在哪里
  • 向我们展示您的 /application/config/database.php 内容
  • 错误信息和插入查询中的表名似乎不同

标签: php database codeigniter phpmyadmin


【解决方案1】:

在您的 database.php 中有 'dbprefix' => '1',,您需要将其更改为 'dbprefix' => '',

【讨论】:

    【解决方案2】:

    您调用了数据库中不存在的表,因此请检查您调用的表名。

    如果你有表单验证库检查规则表的名称可能隐藏在那里哈哈

    放松并享受编程!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-28
      • 2014-03-25
      • 1970-01-01
      • 2016-07-12
      • 2014-05-05
      • 2016-05-18
      • 2012-08-03
      • 2013-08-28
      相关资源
      最近更新 更多