For a project, I'm trying to make an application where users can enter their values, but when I test it on localhost I keep getting this error: warning: mysqli_connect(): (HY000/ 3159): Disable transmission when using an insecure connection --require_secure_transport=ON. This is my php code:
$bedrijfsnaam = $_POST['bedrijfsnaam']; $dag = $_POST['dag']; $caption = $_POST['caption']; var_dump($bedrijfsnaam, $dag, $caption); $dbh = mysqli_connect(hostname: $host, username: $username, password: $password, database: $dbname); if (mysqli_connect_errno()) { die("Connection error: " . mysqli_connect_errno()); } $sql = "INSERT INTO file_upload (bedrijfsnaam, dag, caption) VALUES (?, ?, ?)"; $stmt = mysqli_stmt_init($conn);
Is there a secure way to fix this error since the project must be released and from what I understand it is not safe to turn off secure_transport.
I tried using another external database, which resulted in another error, the connection was actively refused. This code does work because I tried running it on localhost and it does work
P粉9464374742023-12-21 17:42:37
You need to call [mysqli_real_connect][1] and pass in the $mysqli instance as a parameter
$mysqli = mysqli_init(); if (!$mysqli) { die('mysqli_init failed'); } $mysqli->ssl_set( '/path/to/client-key.pem', '/path/to/client-cert.pem', '/path/to/ca-cert.pem', NULL, NULL ); //any paths here will work if (!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) { die('Setting MYSQLI_INIT_COMMAND failed'); } if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) { die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed'); }
Then passed to mysqli_real_connect
$dbh = mysqli_real_connect(mysql:$mysqli, hostname: $host, username: $username, password: $password, database: $dbname); [1]: https://www.w3schools.com/Php/func_mysqli_real_connect.asp