|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74432 mysqli_connect adding ":3306" to $host if $port parameter not given
Submitted: 2017-04-13 11:23 UTC Modified: 2017-04-27 11:22 UTC
Avg. Score:4.1 ± 1.4
Reproduced:8 of 9 (88.9%)
Same Version:6 (75.0%)
Same OS:6 (75.0%)
From: php dot bugs at harry dot lu Assigned: pollita (profile)
Status: Closed Package: MySQLi related
PHP Version: 7.0.18 OS: Linux x86_64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php dot bugs at harry dot lu
New email:
PHP Version: OS:


 [2017-04-13 11:23 UTC] php dot bugs at harry dot lu

This seems to be a regression in 7.0.18. If you give a port in the $host section of mysqli_connect, it will still add ":3306" to the end of it.

> mysqli_connect("", "user", "pass", "schema");
will return:
> mysqli_connect(): (HY000/2002): Failed to parse address ""

Notice the double port assignment. People should be using the $port parameter if mysqli_connect and not giving ports like this, but it still seems like a regression to me. Thanks!

Test script:
# Works in 7.0.17, broken in 7.0.18
mysqli_connect("", "user", "pass", "schema");


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-14 13:16 UTC]
-Assigned To: +Assigned To: pollita
 [2017-04-14 13:16 UTC]
Sara, could you please check? Seems there might be other regressions related to #74216.

 [2017-04-19 09:06 UTC] premavansmuuf at gmail dot com
I _think_ I am having somehow similar problem when using Predis, where I have port defined inside $host variable instead of having it separately in $port.

`Failed to parse address "localhost:6379:" [tcp://localhost:6379:]`

Predis is using `stream_socket_client()` function.

It works in 5.6 but I think it stopped working in new PHP 7 version.
 [2017-04-20 15:20 UTC]
OMG. Why is every use of streams wrong?

Yeah, I'll clean mysqli_connect() up for the "port parameter not used" case.
 [2017-04-20 15:32 UTC]
Oh, and as to predis, that's a bug in predis appending ":$port" when $port doesn't actually contain any value.  Someone should send a pull request regarding these lines:
 [2017-04-20 17:08 UTC]
dig dig dig...

So, this may only be happening to mysqli_connect() if mysqlnd is enabled (which is typical), though in the mysqlnd enabled case it looks like you can't actually use an IPv6 address unless you explicitly wrap it in square brackets.

This rabbit hole keeps getting deeper. :(
 [2017-04-27 10:39 UTC]
-Status: Assigned +Status: Closed
 [2017-04-27 10:39 UTC]
Patch for bug #74432 reverted, thereby this issue is fixed.

 [2017-04-27 10:41 UTC]
Oops, wrong bug number, bug #74216.

 [2017-04-27 11:22 UTC]
Also, please test the release candidates.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 28 19:01:30 2024 UTC