gpt4 book ai didi

php - 连接到 codeigniter 中的另一个数据库并插入

转载 作者:行者123 更新时间:2023-11-28 23:09:45 25 4
gpt4 key购买 nike

我正在尝试连接到另一个数据库并插入数据,数据正确地插入到第一个数据库中但没有插入到第二个数据库中,两个表中的所有字段都相同,下面的代码没有插入latestdb,下面是我的模型代码,我很确定 Controller 和 View 都很好,如果需要更多详细信息,请告诉我。我正在使用 codeigniter 2。问题是在注释之后//Insert in pr_users

$this->db->$function($this->myTables['users'], $data);
$db1['latestdb']['hostname'] = 'localhost';
$db1['latestdb']['username'] = 'root';
$db1['latestdb']['password'] = 'passw';
$db1['latestdb']['database'] = 'latestdb';
$db1['latestdb']['dbdriver'] = 'mysql';
$db1['latestdb']['dbprefix'] = '';
$db1['latestdb']['pconnect'] = TRUE;
$db1['latestdb']['db_debug'] = TRUE;
$db1['latestdb']['cache_on'] = FALSE;
$db1['latestdb']['cachedir'] = '';
$db1['latestdb']['char_set'] = 'utf8';
$db1['latestdb']['dbcollat'] = 'utf8_general_ci';
$db1['latestdb']['swap_pre'] = '';
$db1['latestdb']['autoinit'] = TRUE;
$db1['latestdb']['stricton'] = FALSE;


$DB2 = $this->load->database($db1, TRUE);
$DB2->db_select('zipbizzlatestdb');
$DB2->$function($this->myTables['users'], $data);

$DB2->insert('pr_users',$data);

我收到错误提示:

遇到错误

您尚未选择要连接的数据库类型。

最佳答案

修改

$DB2 = $this->load->database($db1);

// TRUE parameter tells CI that you'd like to return the database object.
$DB2 = $this->load->database($db1, TRUE);

另请注意

You don’t need to create separate database configurations if you only need to use a different database on the same connection. You can switch to a different database when you need to, like this:

$this->db->db_select('database2_name');

$this->$DB2->your_function( ... )

^
Does not have any such property

$DB2->your_function( .. )

关于php - 连接到 codeigniter 中的另一个数据库并插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46298176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com