连接本地数据库正常,连接阿里云虚拟主机上mysql服务器时,mysql方式可以正常连接,mysqli与PDO方式连接时,出现错误
Unexpected exception of type [PDOException] with message [SQLSTATE[HY000] [2005] Unknown MySQL server host
解决方式:连接时不用添加端口
将 return 'mysql:host='.$this->_config['DB_HOST'].':'.$this->_config['DB_PORT'].';dbname='.$this->_config['DB_NAME'];
修改为:
return 'mysql:host='.$this->_config['DB_HOST'].';dbname='.$this->_config['DB_NAME'];