Home >Backend Development >PHP Tutorial >关于dsn的有关问题

关于dsn的有关问题

WBOY
WBOYOriginal
2016-06-13 10:38:07935browse

关于dsn的问题
最近在codeigniter中使用dsn进行数据库连接,但是不管端口号改成什么总是能够连接成功,而修改用户名,密码或ip地址的话就会出现连接失败的问题,下面是我的代码

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->    function get_remote_dblist($ip, $port, $user, $pwd) {        $dsn = "mysql://$user:$pwd@$ip:$port";        $newDB = $this->load->database ( $dsn , TRUE );return $newDB->version();}

烦请各位前辈指点下

------解决方案--------------------
CI的官方文档中并未提及DSN中主机名可以附加端口号。有一个折衷的方法你可以试试
PHP code
$dsn = "mysql://{$user}:{$pwd}@{$ip}/?port={$port}";<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn