php.net |  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
Votes:9
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
 [2017-04-13 11:23 UTC] php dot bugs at harry dot lu
Description:
------------
Hello,

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("127.0.0.1:3306", "user", "pass", "schema");
will return:
> mysqli_connect(): (HY000/2002): Failed to parse address "127.0.0.1:3306:3306"

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:
---------------
<?php
# Works in 7.0.17, broken in 7.0.18
mysqli_connect("127.0.0.1:3306", "user", "pass", "schema");



Patches

Pull Requests

History

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

Thanks.
 [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] pollita@php.net
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] pollita@php.net
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: https://github.com/nrk/predis/blob/6ab10b2b705ea5121f2c1ea87a290f6871c32ebd/src/Connection/StreamConnection.php#L156-L160
 [2017-04-20 17:08 UTC] pollita@php.net
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] ab@php.net
-Status: Assigned +Status: Closed
 [2017-04-27 10:39 UTC] ab@php.net
Patch for bug #74432 reverted, thereby this issue is fixed.

Thanks.
 [2017-04-27 10:41 UTC] ab@php.net
Oops, wrong bug number, bug #74216.

Thanks.
 [2017-04-27 11:22 UTC] ab@php.net
Also, please test the release candidates.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC