0

I'm running in an issue with $mysqli->real_connect . new mysqli is working fine but $mysqli->real_connect brings the following error message. Fatal error: Uncaught Error: Call to a member function prepare() on bool

I don't finde realy much information about $mysqli->real_connect. Anny suggestion what i can do?

<?php

$mysqli = mysqli_init();

$hostaddress = 'xxxxxxx.xxxx';
$db = "xxxxxxxxx";
$username = "xxxxxxxx";
$port = "xxxxx";
$pass = "xxxxxxxxx";
    
    
$mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
$mysqli->ssl_set( "xxxxxxxxxxxxxxx", "xxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxx" , NULL, NULL );
    
$conn = $mysqli->real_connect( $hostaddress, $username, $pass, $db, $port );
$conn=             new mysqli( $hostaddress, $username, $pass, $db, $port );

?>

Solution:

<?php

$conn = mysqli_init();

$hostaddress = 'xxxxxxx.xxxx';
$db = "xxxxxxxxx";
$username = "xxxxxxxx";
$port = "xxxxx";
$pass = "xxxxxxxxx";
    
    
$conn->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
$conn->ssl_set( "xxxxxxxxxxxxxxx", "xxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxx" , NULL, NULL );
    
$conn->real_connect( $hostaddress, $username, $pass, $db, $port );


?>
RunDosRun
  • 1
  • 1
  • Any reason why you are creating another new mysqli object at the end? Looks like mysqli exposes some variables for you to see why the connection failed with real_connect: https://www.php.net/manual/en/mysqli.connect-error.php. The return value of real_connect is a boolean, you're just supposed to keep using the `$mysqli` object to perform queries. – Devon Bessemer May 06 '22 at 18:47
  • Hello, thank you for the information. I just added the second $conn for showing what i put instead for testing. Below works fine but the upper $conn is not working. – RunDosRun May 06 '22 at 18:59
  • Where did you get this idea, `$conn = $mysqli->real_connect`? What does $conn to do here, given you already created a mysqli instance? – Your Common Sense May 06 '22 at 19:16
  • I'm noob thank you for the tip "Your Common Sense 2". Removed $mysqli and put everywhere $conn – RunDosRun May 06 '22 at 19:31

0 Answers0