Skip to content

Wrong error message after switching database context #924

@ramonacat

Description

@ramonacat

PHP Driver version or file name

pdo_sqlsrv 5.3.0

SQL Server version

Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) Aug 22 2017 17:04:49 Copyright (C) 2017 Microsoft Corporation Express Edition (64-bit) on Windows 10 Enterprise 10.0 (Build 16299: ) (Hypervisor)

Client operating system

Windows 10 Enterprise 1709

PHP version

PHP 7.2.12 (cli) (built: Nov 8 2018 05:47:36) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Microsoft ODBC Driver version

10.0.16299.15

Table schema

CREATE DATABASE test;
GO

CREATE DATABASE test2;
GO

Tables are irrelevant.

Problem description

A non-error message that was emitted previously is shown instead of the actual error message.

Expected behavior and actual behavior

Expected: An error message about division by zero is shown.
Actual:

PHP Fatal error:  Uncaught PDOException: SQLSTATE[01000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Changed database context to 'test2'.

Repro code or steps to reproduce

Fill in the DSN to work with your database, but make sure you're not connecting to test2 (so the USE statement will emit a message).

<?php
	$pdo = new \PDO('sqlsrv:Server=localhost;Database=test');
	$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
	$statement = $pdo->prepare('SET NOCOUNT ON; USE test2; SELECT 1/0 AS col1');
	$statement->execute();
	
	var_dump($statement->fetchColumn());

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions