php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61900 Cannot use PDO (dblib) and mssql_ (FreeTDS) in the same script
Submitted: 2012-05-02 12:28 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: stasismedia at gmail dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.3.11 OS: Ubuntu 12.04
Private report: No CVE-ID: None
 [2012-05-02 12:28 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-01 06:26 UTC] ssufficool@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=317653e694c8cd3a3cc4c12c527af584726a66c7
Log: FIX BUG #61900
 [2013-06-01 06:26 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-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=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=317653e694c8cd3a3cc4c12c527af584726a66c7
Log: FIX BUG #61900
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 01:01:28 2024 UTC