我试图在一个代码点火器应用程序中连接多个数据库(Mysql)?但是数据库在不同的服务器上。
CodeIgniter 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 Line: 315函数: require_once
发布于 2019-06-17 12:18:05
文件:guide/database/connecting.html
在application/config/database.php中添加新元素$db数组
$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());
}
}https://stackoverflow.com/questions/56628916
复制相似问题