Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDO: Got error when exec 'DELETE' on something doesn't exist #336

Closed
Gounlaf opened this issue Mar 22, 2017 · 2 comments
Closed

PDO: Got error when exec 'DELETE' on something doesn't exist #336

Gounlaf opened this issue Mar 22, 2017 · 2 comments
Assignees

Comments

@Gounlaf
Copy link

Gounlaf commented Mar 22, 2017

Hi,

I got a weird behavior when I try to delete something that doesn't exist (table exist, but the row I want to deleted doesn't), with pdo driver.
On PHP 5.6, there were no problem.

Bellow a test script and results obtained on this system:

PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies
$ pecl info sqlsrv
About pecl.php.net/sqlsrv-4.0.8
===============================
Release Type          PECL-style PHP extension (source code)
Name                  sqlsrv
Channel               pecl.php.net
Summary               Microsoft Drivers for PHP for SQL Server
                      (SQLSRV)
Description           The Microsoft Drivers for PHP for SQL Server are
                      PHP extensions that allow for the reading and
                      writing of SQL Server data from within PHP
                      scripts. The SQLSRV extension provides a
                      procedural interface while the PDO_SQLSRV
                      extension implements PDO for accessing data in
                      all editions of SQL Server 2005 and later
                      (including Azure SQL DB). These drivers rely on
                      the Microsoft ODBC Driver for SQL Server to
                      handle the low-level communication with SQL
                      Server.
                      *This package contains only the SQLSRV driver.*
Maintainers           Meet Bhagdev <[email protected]> (lead)
                      Jay Kint <[email protected]> (lead,
                      inactive)
                      Marie Barwin <[email protected]> (lead)
                      Hadis Kakanejadi Fard <[email protected]>
                      (lead)
Release Date          2016-12-19 13:12:21
Release Version       4.0.8 (stable)
API Version           4.0.8 (stable)
License               The MIT License (MIT)
                      (https://opensource.org/licenses/mit)
Release Notes         [Added]
                      - Unicode Column name support.
                      [Fixed]
                      - Fixed issue with buffered cursor in PDO_SQLSRV
                      driver when CharacterSet is UTF-8.
                      - Fixed issue with empty output parameters on
                      stored procedure.
                      - Fixed memory leaks in buffered queries.
Required Dependencies PHP version 7.0.0
                      PEAR installer version 1.4.0b1 or newer
                       Operating System
                      OS/Arch matching pattern '//'
package.xml version   2.0
Last Modified         2017-03-16 13:58
Previous Installed    - None -
Version



$ pecl info pdo_sqlsrv

About pecl.php.net/pdo_sqlsrv-4.0.8
===================================
Release Type          PECL-style PHP extension (source code)
Name                  pdo_sqlsrv
Channel               pecl.php.net
Summary               Microsoft Drivers for PHP for SQL Server
                      (PDO_SQLSRV)
Description           The Microsoft Drivers for PHP for SQL Server are
                      PHP extensions that allow for the reading and
                      writing of SQL Server data from within PHP
                      scripts. The SQLSRV extension provides a
                      procedural interface while the PDO_SQLSRV
                      extension implements PDO for accessing data in
                      all editions of SQL Server 2005 and later
                      (including Azure SQL DB). These drivers rely on
                      the Microsoft ODBC Driver for SQL Server to
                      handle the low-level communication with SQL
                      Server.
                      *This package contains only the PDO_SQLSRV
                      driver.*
Maintainers           Meet Bhagdev <[email protected]> (lead)
                      Jay Kint <[email protected]> (lead,
                      inactive)
                      Marie Barwin <[email protected]> (lead)
                      Hadis Kakanejadi Fard <[email protected]>
                      (lead)
Release Date          2016-12-19 13:12:19
Release Version       4.0.8 (stable)
API Version           4.0.8 (stable)
License               The MIT License (MIT)
                      (https://opensource.org/licenses/mit)
Release Notes         [Added]
                      - SQLSRV_ATTR_FETCHES_NUMERIC_TYPE attribute
                      support.
                      - Unicode Column name support.
                      [Fixed]
                      - Fixed precision issues when double data type
                      returned as strings using buffered queries.
                      - Fixed issue with buffered cursor in PDO_SQLSRV
                      driver when CharacterSet is UTF-8.
                      - Fixed segmentation fault in error cases when
                      error message is returned with emulate prepare
                      attribute is set to true.
                      - Fixed issue with empty output parameters on
                      stored procedure.
                      - Fixed memory leaks in buffered queries.
Required Dependencies PHP version 7.0.0
                      PEAR installer version 1.4.0b1 or newer
                       Operating System
                      OS/Arch matching pattern '//'
package.xml version   2.0
Last Modified         2017-03-16 13:58
Previous Installed    - None -
Version
<?php
define("DB_HOST", "127.0.0.1");
define("DB_PORT", "12345");
define("DB_NAME", "dbName");
define("DB_USER", "dbUser");
define("DB_PASS", "dbPass");

$sql = "DELETE FROM foo_table WHERE id = 42";
$sqlWithParameter = "DELETE FROM foo_table WHERE id = :id";
$sqlParameter = 42;


$dsn = 'sqlsrv:Server=' . DB_HOST . ',' . DB_PORT . ';Database=' . DB_NAME;
$options = array();
$dbh = new PDO($dsn, DB_USER, DB_PASS, $options);

echo 'PDO:sqlsrv' . PHP_EOL;

echo 'prepare, not args' . PHP_EOL;
$stmt = $dbh->prepare($sql);
var_dump($stmt->execute());
echo "errorCode: " . $dbh->errorCode() . PHP_EOL;
echo "errorInfo: " . print_r($dbh->errorInfo(), true);

echo 'prepare, with args' . PHP_EOL;
$stmt = $dbh->prepare($sqlWithParameter);
var_dump($stmt->execute(array(':id' => $sqlParameter)));

echo "errorCode: " . $dbh->errorCode() . PHP_EOL;
echo "errorInfo: " . print_r($dbh->errorInfo(), true);

echo 'direct exec' . PHP_EOL;
var_dump($dbh->exec($sql));

echo "errorCode: " . $dbh->errorCode() . PHP_EOL;
echo "errorInfo: " . print_r($dbh->errorInfo(), true);
PDO:sqlsrv
prepare, not args
bool(true)
errorCode: 00000
errorInfo: Array
(
    [0] => 00000
    [1] => 
    [2] => 
)
prepare, with args
bool(true)
errorCode: 00000
errorInfo: Array
(
    [0] => 00000
    [1] => 
    [2] => 
)
direct exec
bool(false)
errorCode: HY010
errorInfo: Array
(
    [0] => HY010
    [1] => 0
    [2] => [unixODBC][Driver Manager]Function sequence error
)

If you need more informations / test...

Thanks

@yukiwongky
Copy link
Contributor

yukiwongky commented Mar 22, 2017

We are able to reproduce the issue on Linux; PHP7 on Windows do not seem to have the error. We will investigate on this and get back to you.

@yukiwongky
Copy link
Contributor

The fix should be in the latest release (4.1.8-preview). Please check to see if your problem still exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants