dsagzmosl32217092 2019-04-12 08:36
浏览 61

发现与PHP连接到远程数据库(MySQL)

We use 2 servers on CentOS. One with the PHP Code and the other with our database (MariaDB). We tried to connect them, but doesn't work in PHP and work with CLI Mysql, with the same credential. We created a special user to connect. We use a custom framework to connect to the database.

Everything work when we are on local (on a physical machine, not on server)

PHP version : 5.4.16

We tried a phpinfo(); : Mysql and Mysqli is activated. Connection to the MySQL serveur with CLI work.

    define('DBNAME', 'start-up');
    define('DBHOST', '10.13.200.13');
    define('DBUSER', 'gestions');
    define('DBPASSWORD', 'gestionPass');

From the custom framework :

    protected static $db = false;
    private static $last;
    private static $prep;

    //La dernière requete effectuée
    private static $error = null;

    private static $user;
    private static $password;
    private static $name;
    private static $host;

 public function __construct()
    {
        if (self::$db === false) {
            $dsn            = 'mysql:dbname=' . DBNAME . ';host=' . DBHOST;
            self::$user     = DBUSER;
            self::$password = DBPASSWORD;
            self::$name     = DBNAME;
            self::$host     = DBHOST;

            self::$db = parent::__construct($dsn, self::$user, self::$password);
        }
    }

+-------------------------------------------------------------------------------                                                                                                                                                             ------------------------------------+
| Grants for gestions@10.13.200.13                                                                                                                                                                                                                                                |
+-------------------------------------------------------------------------------                                                                                                                                                             ------------------------------------+
| GRANT USAGE ON . TO 'gestions'@'10.13.200.13' IDENTIFIED BY PASSWORD '*XXXXXX' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON database.* TO 'gestions'@'10.13.200.13'                                                                                                                                                                                                    |
+-------------------------------------------------------------------------------                                                                                                                                                             ------------------------------------+
2 rows in set (0.01 sec)

I don't really know what to show to you.

I expect to connect my PHP to my MySQL server.

Thanks a lot !

--- EDIT ---

That's a mistake. I put my local code, the code on the VM is the real IP.

Adding my user (Probably the problem ?)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧