php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64338 pdo_dblib can't connect to Azure SQL
Submitted: 2013-03-02 15:29 UTC Modified: 2013-03-04 16:05 UTC
Votes:4
Avg. Score:4.5 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mah at everybody dot org Assigned:
Status: Closed Package: MSSQL related
PHP Version: 5.5.0alpha5 OS: any
Private report: No CVE-ID:
 [2013-03-02 15:29 UTC] mah at everybody dot org
Description:
------------
The SQL database available on Azure apparently does not have the same
connection semantics as SQL Server.  “use DATABASE” is not possible — it
returns an error saying that you should open a new connection if you
want a new database.

This is confusing when you are using the DBLIB connector because it is
the DBLIB connection code that does the “use”, not the developer's PHP
code.

The FreeTDS people recognized this a while back:

    About a year ago we added the DBSETLDBNAME macro as a way to set the
    dbname in the db-lib LOGINREC.  That sets the dbname in the login
    packet, obviating the need for "USE dbname".

    http://lists.ibiblio.org/pipermail/freetds/2012q4/028168.html

The attached patch makes use of DBSETLDBNAME and eliminates the USE.


Test script:
---------------
<?php

try {
    $server = "SERVER.database.windows.net:1433";
    $username = "USER@SERVER";
    $password = "PASSWORD";
    $dbname = "DBNAME";
    $mssql = new PDO("dblib:host=$server;dbname=$dbname",$username,$password);
    echo "Success!\n";
}
catch ( PDOException $e ) {
   print( "Error connecting to SQL Server." );
   die(print_r($e));
}



Patches

pdo_dblib.patch (last revision 2013-03-04 16:00 UTC) by mah at everybody dot org)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-02 15:57 UTC] mah at everybody dot org
Originally reported to Debian: http://bugs.debian.org/702079
 [2013-03-02 16:56 UTC] pajoye@php.net
I suppose you are on Linux as dblib is not supported anymore on windows since 
quite a while.

If you are on win usw sqlsrv, works out of the box.
 [2013-03-02 16:56 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2013-03-02 17:30 UTC] pajoye@php.net
btw, DBSETLDBNAME could be easily added in pdo_dblib_handle_factory 
(ext/pdo_dblib/dblib_driver.c).

Can you test it pls? if you could create a patch and test it, even better :)
 [2013-03-02 19:36 UTC] mah at everybody dot org
Yes, this is on Linux.  If you're using Azure to host your Linux machine (which I am), it makes sense to use the Azure-hosted SQL database if you can.

I've already attached a patch and tested the patch that does exactly what you suggest.
 [2013-03-02 19:36 UTC] mah at everybody dot org
-Status: Feedback +Status: Open
 [2013-03-04 16:05 UTC] mah at everybody dot org
Updated the patch to fix a segfault that I observed when I turned on FreeTDS' debug log. See http://lists.ibiblio.org/pipermail/freetds/2013q1/028280.html
 [2013-06-01 05:58 UTC] ssufficool@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0e2bcf3373d914a215784c041a2a4c3b6afc2034
Log: FIX BUG #64338, #64808, #63638
 [2013-06-01 05:58 UTC] ssufficool@php.net
-Status: Open +Status: Closed
 [2013-06-04 03:40 UTC] ssufficool@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d8f938c78478c211dc3b5609e9f37d2e2c47896f
Log: FIX BUG #55647, #60512, #60512, #61900, #64338, #64808, #63638
 [2013-06-04 05:03 UTC] stas@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d8f938c78478c211dc3b5609e9f37d2e2c47896f
Log: FIX BUG #55647, #60512, #60512, #61900, #64338, #64808, #63638
 [2013-06-11 16:48 UTC] mah at everybody dot org
Could we get this fix backported?
 [2013-10-06 01:27 UTC] ssufficool@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9c7dbb0487f5991fde03873ea8f5e66d6688415f
Log: Fix bug #64338 pdo_dblib can't connect to Azure SQL
 [2013-11-17 09:30 UTC] laruence@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9c7dbb0487f5991fde03873ea8f5e66d6688415f
Log: Fix bug #64338 pdo_dblib can't connect to Azure SQL
 [2013-11-17 09:31 UTC] laruence@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d8f938c78478c211dc3b5609e9f37d2e2c47896f
Log: FIX BUG #55647, #60512, #60512, #61900, #64338, #64808, #63638
 [2013-11-17 09:31 UTC] laruence@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0e2bcf3373d914a215784c041a2a4c3b6afc2034
Log: FIX BUG #64338, #64808, #63638
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 10:02:09 2014 UTC