0

So, when I try to create the connection without the flag, it works just fine.

$db_init_conn = mysqli_init();
$db_conn = mysqli_real_connect($db_init_conn, HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE);

But when I use the flag like this.

$db_init_conn = mysqli_init();
$db_conn = mysqli_real_connect($db_init_conn, HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE,$flags=MYSQLI_CLIENT_INTERACTIVE);

I got this

Warning: mysqli_real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.

What did I do wrong?

UPDATE

It also happens when I use other flags

$mysqli = mysqli_init();DBPASSWORD,DATABASE); 
$db_conn = mysqli_real_connect($mysqli, HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE, $flags=MYSQLI_CLIENT_COMPRESS); 
user3783243
  • 5,368
  • 5
  • 22
  • 41
Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108
  • Is MySQL running on the HOSTNAME? – RiggsFolly Jun 14 '20 at 13:30
  • Of course it is. That's why it is working when I did not use the flag. – Aminah Nuraini Jun 14 '20 at 13:31
  • not a mysqli user myself, still : are u certain you need the `$flags=foo` assignment ? seems to me the api is not 'key-value-paired' , so would receive FLAG_AS_INT for next parameter, that is port. – YvesLeBorg Jun 14 '20 at 13:39
  • I am certain I need the flag. How can I use it? – Aminah Nuraini Jun 14 '20 at 13:42
  • Yes, I did. I got connection refused too – Aminah Nuraini Jun 14 '20 at 13:44
  • not sure : am not tooled to try it at the moment. maybe ``mysqli_real_connect($mysqli,HOSTNAME,DBUSERNAME,DBPASSWORD,DATABASE,,, MYSQLI_CLIENT_INTERACTIVE); `... ymmv, i never used mysqli, so have no real knowledge, but it is what the api docs suggests to me. – YvesLeBorg Jun 14 '20 at 13:44
  • It gives me `Parse error: syntax error, unexpected ','` – Aminah Nuraini Jun 14 '20 at 13:46
  • I don't know why they put the flags after the ports and sockets. That seems like a bad design. Only example I found has default port set and NULL for socket, https://books.google.com/books?id=Yat0DYXpUj8C&pg=PA53&lpg=PA53&dq=MYSQLI_CLIENT_INTERACTIVE+php+set&source=bl&ots=2O-eUZRMGV&sig=ACfU3U2n-0LJ6CiGHrtd-VG83MNtEbbjfg&hl=en&sa=X&ved=2ahUKEwibsKzQuYHqAhV5TDABHYhxBYQQ6AEwBXoECB0QAQ#v=onepage&q=MYSQLI_CLIENT_INTERACTIVE%20php%20set&f=false. (might be time to consider PDO, flags are in a logical position there) – user3783243 Jun 14 '20 at 13:52

1 Answers1

1

so, quick installed mysqli on my box, and this gave me no errors

    $db_init_con = mysqli_init();
    mysqli_real_connect($db_init_con , "127.0.0.1" , "***REDACTED***" , "***REDACTED***" , "notifications" , 3306 ,null , MYSQLI_CLIENT_INTERACTIVE);

with mysql 5.7, php 7.2.6, osx

YvesLeBorg
  • 9,070
  • 8
  • 35
  • 48