codeigniter获取另一个数据库的视图表

p4rjhz4m  于 2021-06-15  发布在  Mysql
关注(0)|答案(2)|浏览(290)

在开发过程中,我们必须对另一个数据库的视图表进行签名,但无论我们如何努力,只会出现一个错误。所以即使我称之为简单的选择,也会出现一个错误。
发生数据库错误
错误号:1046未选择数据库

SELECT * 
FROM `test1`.`view_test_table`

文件名:test.php
我不明白这种情况。
我已经完成了所有我要求codeigniter文档做的事情,从简单的查询到查询生成器测试,但是我看不到细节。
test\u mode.php是:

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Test_model extends CI_Model
{
    private $new_db;

    function __construct()
    {
        parent::__construct();
        $this->new_db = $this->load->database('test1', TRUE);
    }

    public function test_view_list()
    {
       $this->new_db->select("*");
       $this->new_db->from("test1.view_test_table");
       return $this->new_db->get()->result_array();
    }
}

和database.php

$db['test1'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'test1',
    'password' => 'xxxx',
    'database' => '',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    '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
 );

我犯了什么错误吗?

9rbhqvlz

9rbhqvlz1#

在database.php文件中。写下你的数据库名。

$db['test1'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'test1',
    'password' => 'xxxx',
    'database' => 'databasename',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    '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
 );
vbkedwbf

vbkedwbf2#

尝试为此数据库使用新示例

$new_db = $this->load->database('test1', TRUE);

并参考表格 view_test_table 使用新的数据库

相关问题