php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34072 MySQL module can't connect if port is not 3306
Submitted: 2005-08-10 18:11 UTC Modified: 2005-09-08 01:00 UTC
Votes:19
Avg. Score:3.7 ± 1.4
Reproduced:14 of 16 (87.5%)
Same Version:8 (57.1%)
Same OS:9 (64.3%)
From: pash_ka at fonbet dot info Assigned: wez (profile)
Status: No Feedback Package: PDO related
PHP Version: 5CVS-2005-08-30 OS: Windows XP
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pash_ka at fonbet dot info
New email:
PHP Version: OS:

 

 [2005-08-10 18:11 UTC] pash_ka at fonbet dot info
Description:
------------
I can't connect with my MySQL server running on localhost using non-standart port.
I've tried dsn
mysql:host=localhost;port=6733;dbname=www
(resulted with "Can't connect to MySQL server on 'localhost' (10061)" error)
mysql:host=localhost:6733;dbname=www
(resulted with "Unknown MySQL server host 'localhost:6733' (11001)" error)

I've also tried to use
ini_set('mysql.default_port', 6733);
and set in php.ini

I've tried it with PHP 5.1 beta3 and with php_pdo_mysql.dll from "php5-win32-latest.zip" (09.08.2005).


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-10 18:16 UTC] pash_ka at fonbet dot info
And yes, I've tried with port 3306 - it works fine. And it also works fine with my non-standart port using mysql_connect().
So it's definetly a bug or missing future in PDO.
 [2005-08-10 18:22 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

Can't reproduce.
 [2005-08-10 18:38 UTC] pash_ka at fonbet dot info
Well, I've just downloaded php5-win32-latest.zip - it's the same one (Aug 9 2005 ) and tried with it. The bug is still there for me.
Do i need to use "mysql:host=localhost;port=6733;dbname=www" dsn or there is another syntax to specify port?
 [2005-08-10 18:44 UTC] tony2001@php.net
I've just copied your DSN and it worked for me.
But IIRC it's possible that it automagically uses local socket on my Linux, which is not available on Win32.

 [2005-08-10 18:44 UTC] tony2001@php.net
Wez, could you plz check it out?
 [2005-08-30 01:05 UTC] iliaa@php.net
Does it work if you change the hostname to 127.0.0.1?
 [2005-08-30 12:00 UTC] pash_ka at fonbet dot info
I've tried it with latest (Aug 30 2005 08:37:40) build, and using 127.0.0.1 instead of localhost works.

I'm using this test script:
-------------------------------------------
<?php
if(!isset($argv)){
  header('Content-type: text/plain');
  header("Content-Disposition: inline; filename=dbotest.txt");
}

$cfg['host'] = 'localhost';
//$cfg['host'] = '127.0.0.1';
$cfg['port'] = 6733;
$cfg['database'] = 'www-new';
$cfg['username'] = 'pasha';
$cfg['password'] = '****';

connect_mysql($cfg);
echo "\n";
connect_pdo_mysql($cfg);

function connect_mysql($cfg){
  $dsn = $cfg['host'].':'.$cfg['port'];
  echo "Connecting to MYSQL (DSN = {$dsn}).\n";
  @$res = mysql_connect($dsn, $cfg['username'], $cfg['password']);
  echo 'Result: '.($res?'OK':mysql_error())."\n";
  return $res;
}
function connect_pdo_mysql($cfg){
  $dsn = "mysql:host={$cfg['host']};port={$cfg['port']};dbname={$cfg['database']}";
  echo "Connecting to PDO_MYSQL (DSN = {$dsn}).\n";
  try{
    $res = new PDO($dsn, $cfg['username'], $cfg['password']);
    echo "Result: OK\n";
    return $res;
  }catch(PDOException $ex){
    echo 'Result: '.$ex->getMessage()."\n";
    return false;
  }
}
?>
-------------------------------------------

And this is the result when using localhost:
------------------------------------------
Connecting to MYSQL (DSN = localhost:6733).
Result: OK

Connecting to PDO_MYSQL (DSN = mysql:host=localhost;port=6733;dbname=www-new).
Result: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'localhost' (10061)
------------------------------------------
 [2005-08-30 12:22 UTC] pash_ka at fonbet dot info
I've also checked it with version 5.1.0b3 (Jul 14 2005 20:32:24), and it works fine for 127.0.0.1
 [2005-08-31 06:07 UTC] gschlossnagle@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

try a new 5.1 snapshot please.  Your bug is only occurs when 
you use 'localhost' (and not 127.0.0.1), so please check that.

Thanks,

George
 [2005-09-08 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2006-08-13 11:50 UTC] waruiinu at gmail dot com
I think there is some sort of bug in mysql client library. It just doesn't want to use tcp connection if you connect to localhost. For example if I add -P 3306 to mysql client binary, netstat will show the unix connection, not the tcp. Only if i use -h 127.0.0.1 mysql will use tcp (-h localhost doesn't solve anything).
 [2007-10-22 07:11 UTC] shanewaj at gmail dot com
Hi Friends 
I am trying to connect a mysql and php5 with Apache2
PHP is working ok 
I can show php files no problem 
but when i try to connect with mysql 
nothing is happending 
simply nothing as I have tried this script as well 
I have tried my old scripts as well 
not no response it does not show any thing 
not even error msg. 
any idea I am lost ...
Thanks 
Shanewaj
 [2007-11-16 22:08 UTC] stratsnteles at wi dot rr dot com
I've installed Apache 2.2, PHP5 and mysql 5.0.45. I have verified that Apache is running fine, along with PHP (running PHP test script). When I use various sample php scripts to connect to mysql, I get nothing. nada. zip. Not even 'die' error message. I'm suspecting it's a problem w/PHP 5. I am a PHP/MySql newbie, but an old PC pro. I am certain that I have the servers configured properly, Can anyone help?
 [2008-06-07 06:38 UTC] m6mkiller at hotmail dot com
yo im not able to connect it says localhost not alowwed to access this and i cant access my servers or any thing i had to use mysql its like it deleted the server name
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 21:01:27 2025 UTC