I want to modify a project to make use of SSL for mysql connections. I managed to create a working ssl connection. But I cannot manage to recreate $handler as the same object/connection as before, so the rest of the source code is not working. How can I accomplish that $handler is exactly the same kind of object as before?
Original code:
$handler = @new mysqli($host, $settings['user'], $settings['password'], $settings['database'], $port);
I changed code to:
$db = mysqli_init();
mysqli_options($db, MYSQLI_CLIENT_SSL, true);
mysqli_options($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, false);
mysqli_ssl_set($db, NULL, NULL, '/usr/local/www/dbssl/mosdb.ca.pem', NULL, NULL);
mysqli_ssl_set($db, '/usr/local/www/dbssl/mosdb.client-key.pem', '/usr/local/www/dbssl/mosdb.client-cert.pem', '/usr/local/www/dbssl/mosdb.ca.pem', NULL, NULL);
$handler = @mysqli_real_connect($db, $host, $settings['user'], $settings['password'], $settings['database'], $port, NULL, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
The answer should be that I should change the code to this if I want the same kind of object for the $handler:
$handler = mysqli_init();
$handler->options(MYSQLI_CLIENT_SSL, true);
$handler->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, false);
$handler->ssl_set(NULL, NULL, '/usr/local/www/dbssl/mosdb.ca.pem', NULL, NULL);
$handler->real_connect($host, $settings['user'], $settings['password'], $settings['database'], $port, NULL, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);