我试图在单个代码点火器应用程序中连接多个数据库(mysql(?但是数据库位于不同的服务器中。
代码点火器 3.x
遇到 PHP 错误严重性:警告
消息: mysqli::real_connect((: (HY000/2002(: 连接超时
文件名: mysqli/mysqli_driver.php
行号:203
回溯:
文件:/var/www/html/rmp/mautic_sync/mautic_ci/application/controllers/Cron.php 行: 19 功能:数据库
文件:/var/www/html/rmp/mautic_sync/mautic_ci/index.php 行: 315 功能:require_once
文档:https://www.codeigniter.com/user_guide/database/connecting.html
在应用程序/配置/数据库中$db数组添加新元素.php
$db['old'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => 'xxxxx', 'database' => 'you_database_name', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8mb4', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );
用:
class YourController extends CI_Controller {
private $old_db = "";
function __construct() {
parent::__construct();
$this->old_db = $this->load->database('old', true);
}
public function index(){
$query = $this->old_db->get('table_name');
print_r($query->result());
}
}