douzhang5295 2018-11-08 14:11
浏览 130

PDO通过隧道连接到外部数据库

I'd like to ask you, how to connect to an external database via tunnel using PDO?

My Database class is:

<?php 

    class Database {

        //Server Params
        private $server_addres = 'xx.xx.xx';
        private $port = '222';
        private $user = 'myuser';
        private $pass = 'mypass';

        //DB Params 
        private $host = '127.0.0.1';
        private $db_name = 'mydbname';
        private $username = 'mydbuser';
        private $password = 'mydbpassowrd';
        private $conn;

        //DB Connect
        public function connect() {
            $this->conn = null;

            try {

                //???
                shell_exec();

                $this->conn =  new PDO('mysql:host='.$this->host.';dbname='.$this->db_name, $this->username, $this->passowrd);
                $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            } catch( PDOException $e ) {
                echo 'Connection Error: ' . $e->getMessage();
            } 

            return $this->conn;
        }
    }

Should I use shell_exec() function, if yes how?

Thank you for your help!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器