在php中的ssl上的Mysqli连接

时间:2015-09-16 11:22:40

标签: php ssl mysqli

制作此代码进行测试:

include_once ('includes.inc.php');

$mysqli = mysqli_init();
if (!$mysqli) {
    die("mysqli_init failed");
    exit;
}

$mysqli->ssl_set($mysqli, '/etc/mysql/ssl/server.key',
                          '/etc/mysql/ssl/server.crt',
                          '/etc/mysql/ssl/server.crt',
                           NULL,
                           NULL);

if (!$mysqli->real_connect(dbhost, dbusername, dbpassword, dbname, 3306, null, MYSQLI_CLIENT_SSL)){
   die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
} else {
   echo "Test connections";
}

在includes.inc.php我定义了db info(name,user,pass ...),它运行正常。 我想在__construct中使用它来创建db类,但它没有用。

在SSL之前我在课堂上使用它:

    public function __construct(){
        /*
         * connect to database server and select the database
         */
        self::$mysqli = new mysqli(dbhost, dbusername, dbpassword, dbname);

        /*
         * check for errors
         */
        if (self::$mysqli->connect_error) {
            die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
            exit;
        }
    }

我需要帮助用ssl连接制作__construct。 TNX ...

0 个答案:

没有答案