Edit report at https://bugs.php.net/bug.php?id=61900&edit=1

 ID:                 61900
 Updated by:         ssuffic...@php.net
 Reported by:        stasismedia at gmail dot com
 Summary:            Cannot use PDO (dblib) and mssql_ (FreeTDS) in the
                     same script
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            PDO related
 Operating System:   Ubuntu 12.04
 PHP Version:        5.3.11
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of ssufficool
Revision: 
http://git.php.net/?p=php-src.git;a=commit;h=317653e694c8cd3a3cc4c12c527af584726a66c7
Log: FIX BUG #61900


Previous Comments:
------------------------------------------------------------------------
[2012-05-02 12:28:17] stasismedia at gmail dot com

Description:
------------
When using PDO (dblib) and mssql_ (FreeTDS) in the same script, PDO will not 
throw any Exceptions.

This is apparently due to the calls to 'dberrhandle' in the FreeTDS library:

https://github.com/php/php-src/blob/master/ext/mssql/php_mssql.c#L598
https://github.com/php/php-src/blob/master/ext/pdo_dblib/pdo_dblib.c#L205


Regardless of the order in the PHP Script, php_mssql is executed last, which 
will replace any error handler function that pdo_dblib has set.

This also seems to be the case when 'forcing' the use of multiple connections.

Whilst using both functions is a silly thing to do, we are migrating a 9 year 
old project over to PDO in a number of phases.

Test script:
---------------
<?php
/*
 * Setup an MSSQL connection (FreeTDS library)
 * It does not matter if this is executed before or after the PDO object is
 * instantiated.
 */
$mssql = mssql_connect('server', 'user', 'pass');

$pdo = new PDO('dblib:host=server;dbname=db', 'user', 'pass');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

try
{
    $pdo->query('INSERT INTO incorrecttable (abc) VALUES (123)');
    echo "Exception not thrown\n";
}
catch(\PDOException $exception)
{
    echo "Exception caught\n";
}

Expected result:
----------------
Exception caught

Actual result:
--------------
Warning: PDO::query(): message: Invalid object name 'incorrecttable'. (severity 
16) in /tmp/php-test/pdotest.php on line 15

Call Stack:
    0.0001     631912   1. {main}() /tmp/php-test/pdotest.php:0
    0.0557     633632   2. PDO->query() /tmp/php-test/pdotest.php:15


Warning: PDO::query(): General SQL Server error: Check messages from the SQL 
Server (severity 16) in /tmp/php-test/pdotest.php on line 15

Call Stack:
    0.0001     631912   1. {main}() /tmp/php-test/pdotest.php:0
    0.0557     633632   2. PDO->query() /tmp/php-test/pdotest.php:15

Exception not thrown


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61900&edit=1

Reply via email to