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

[php7/oci] Showcase of 💥 #18425

Closed
DeepDiver1975 opened this issue Aug 19, 2015 · 23 comments
Closed

[php7/oci] Showcase of 💥 #18425

DeepDiver1975 opened this issue Aug 19, 2015 · 23 comments

Comments

@DeepDiver1975
Copy link
Member

<?php
require 'vendor/autoload.php';

$config = new \Doctrine\DBAL\Configuration();
//..
$connectionParams = array(
        'dbname' => 'XE',
        'user' => 'autotest',
        'password' => 'owncloud',
    'host' => '10.0.0.7',
    'port' => 1521,
        'driver' => 'oci8',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);

$conn->connect();

$conn->executeUpdate('DROP TABLE TEST');
$conn->executeUpdate('CREATE TABLE TEST(A VARCHAR2(4000) NOT NULL, B VARCHAR2(4000) NOT NULL, C VARCHAR2(4000) NOT NULL)');

$conn->insert('TEST', [
    'A' => '1',
    'B' => '2',
    'C' => '3']);

$all = $conn->fetchAll('select * from TEST');
var_dump($all);
deepdiver@alien:~/Development/ownCloud/php7-mysql$ php --version
PHP 5.6.12-1 (cli) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans
    with blackfire v1.1.0, https://blackfire.io/, by SensioLabs
deepdiver@alien:~/Development/ownCloud/php7-mysql$ php test.php 
XDebug could not open the remote debug file '/tmp/xdebug.log'.
array(1) {
  [0] =>
  array(3) {
    'A' =>
    string(1) "1"
    'B' =>
    string(1) "2"
    'C' =>
    string(1) "3"
  }
}
deepdiver@alien:~/Development/ownCloud/php7-mysql$ phpenv local 7.0.0beta3
deepdiver@alien:~/Development/ownCloud/php7-mysql$ php --version
PHP 7.0.0beta3 (cli) (built: Aug 17 2015 17:19:56) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
deepdiver@alien:~/Development/ownCloud/php7-mysql$ php test.php 
array(1) {
  [0]=>
  array(3) {
    ["A"]=>
    string(1) "3"
    ["B"]=>
    string(1) "3"
    ["C"]=>
    string(1) "3"
  }
}
@DeepDiver1975 DeepDiver1975 added this to the 8.2-current milestone Aug 19, 2015
@DeepDiver1975
Copy link
Member Author

So is it a related to doctrine and php7 - or php7 only?

@MorrisJobke
Copy link
Contributor

@DeepDiver1975 Propose this as test case to doctrine? 🙈

@DeepDiver1975
Copy link
Member Author

@DeepDiver1975 Propose this as test case to doctrine? 🙈

No - because the values are fine until doctrine passes them to oci .... looks like a bug to be reported to php ...

@DeepDiver1975
Copy link
Member Author

Upstream report: https://bugs.php.net/bug.php?id=70302

@DeepDiver1975
Copy link
Member Author

pure oci script shows it's a doctrine error - sweet shit

<?php

function e($e) {
    if (!$e) {
        $e = oci_error();
        var_dump($e);
        exit;
    }
}

$conn = oci_connect('autotest', 'owncloud', '172.17.0.1/XE');
e($conn);

// drop table
$stid = oci_parse($conn, 'DROP TABLE TEST');
e($stid);
$r = oci_execute($stid);
e($r);

// create
$stid = oci_parse($conn, 'CREATE TABLE TEST(A VARCHAR2(4000) NOT NULL, B VARCHAR2(4000) NOT NULL, C VARCHAR2(4000) NOT NULL)');
e($stid);
$r = oci_execute($stid);
e($r);

// insert
$stid = oci_parse($conn, 'INSERT INTO TEST (A, B, C) VALUES(:a, :b, :c)');
e($stid);
$a = 1;
$b = 2;
$c = 3;
oci_bind_by_name($stid, ':a', $a);
oci_bind_by_name($stid, ':b', $b);
oci_bind_by_name($stid, ':c', $c);
$r = oci_execute($stid);  // executes and commits
e($r);

// select
$stid = oci_parse($conn, 'SELECT * FROM TEST');
e($stid);
$r = oci_execute($stid);  // executes and commits
e($r);
$data = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
var_dump($data);

@DeepDiver1975
Copy link
Member Author

Issue as reported in the doctrine issue tracker - http://www.doctrine-project.org/jira/browse/DBAL-1283

@DeepDiver1975
Copy link
Member Author

I'm out of this game ... I don't get it

@DeepDiver1975
Copy link
Member Author

Looks like the issue got nailed down a bit more - https://bugs.php.net/bug.php?id=71148

@ghost ghost modified the milestones: 9.1-next, 9.0-current Feb 22, 2016
@LukasReschke
Copy link
Member

Considered not a bug by PHP:

[2016-02-22 04:41 UTC] sixd@php.net
Looks like an expected change with PHP 7.

OCI8 needs the zval of the bound variable to be available when OCIExecute is called.
Try using pass by reference in your bindValue() function, or don't bind in a function.
This is similar to example #3 in http://php.net/manual/en/function.oci-bind-by-name.php

From the dev who analyzed this:

"Reason for this new behavior in PHP 7 is that, unlike in PHP 5.6, zval (_zend_value) in PHP 7.0 is no more have reference count field. Only its values field (zend_value) has reference count field.

Since we store the placeholder (i.e., zval variable) [not its content (zend_value)] in php_oci_bind
structure, it gets overwritten when oci_bind_by_name() is called with same variable and different content in it."

@mmucklo
Copy link

mmucklo commented Mar 4, 2016

Any workarounds?

@DeepDiver1975
Copy link
Member Author

This has to be fixed upstream - doctrine/dbal#2262

@deeky666
Copy link

@DeepDiver1975 just tried out your example with Doctrine master:

<?php

namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8;

use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\Tests\DbalFunctionalTestCase;

class StatementTest extends DbalFunctionalTestCase
{
    protected function setUp()
    {
        if (! extension_loaded('oci8')) {
            $this->markTestSkipped('oci8 is not installed.');
        }

        parent::setUp();

        if (! $this->_conn->getDriver() instanceof Driver) {
            $this->markTestSkipped('oci8 only test.');
        }
    }

    public function testPhp7()
    {
        try {
            $this->_conn->executeUpdate('DROP TABLE TEST');
        } catch (\Exception $e) {}
        $this->_conn->executeUpdate('CREATE TABLE TEST(A VARCHAR2(4000) NOT NULL, B VARCHAR2(4000) NOT NULL, C VARCHAR2(4000) NOT NULL)');

        $this->_conn->insert('TEST', [
            'A' => '1',
            'B' => '2',
            'C' => '3']);

        $all = $this->_conn->fetchAll('select * from TEST');
        var_dump($all);
    }
}
deeky@98N-MUELLER-STEVE:~/dev/doctrine/dbal$ php -v
PHP 7.0.2 (cli) (built: Jan 22 2016 09:57:10) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
deeky@98N-MUELLER-STEVE:~/dev/doctrine/dbal$ vendor/bin/phpunit -c oci8.phpunit.xml tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php 
PHPUnit 5.4.6 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)array(1) {
  [0]=>
  array(3) {
    ["A"]=>
    string(1) "3"
    ["B"]=>
    string(1) "3"
    ["C"]=>
    string(1) "3"
  }
}


Time: 305 ms, Memory: 4.00MB

OK (1 test, 0 assertions)

Weird I don't get an error...

@deeky666
Copy link

@DeepDiver1975 ah nevermind I thought this was about ORA-24816: Expanded non LONG bind data supplied after actual LONG or LOB column but it is about the binding references. Just ignore then...

@DeepDiver1975
Copy link
Member Author

looks like out of scope for 9.1 -> move to 9.2

@dragotin @PVince81 we should add this to the docs/release notes: oracle and php7 don't play well with each other

@DeepDiver1975 DeepDiver1975 modified the milestones: 9.2-next, 9.1-current Jun 30, 2016
@deeky666
Copy link

@DeepDiver1975 we are working hard on this and I think we are close to a solution. As soon as we got this fixed I will tag a new DBAL release.

@DeepDiver1975
Copy link
Member Author

Thanks a lot @deeky666 - we are on 2.5.4 at the moment - can we discuss to backport this fix to the 2.5 branch? Happy to help out. Cheers

@deeky666
Copy link

@DeepDiver1975 yes we will backport this to 2.5.

@PVince81
Copy link
Contributor

PVince81 commented Nov 4, 2016

@DeepDiver1975 Any update ? Still an issue ?

@DeepDiver1975
Copy link
Member Author

@DeepDiver1975 Any update ? Still an issue ?

Still waiting for dbal 2.6 being released - up to now there have been no backports of the necessary fixes to 2.5.x

@DeepDiver1975
Copy link
Member Author

fixed with #26946

@deeky666
Copy link

@DeepDiver1975 this should have been fixed with 2.5.5 already.

@DeepDiver1975
Copy link
Member Author

If I remember correctly we still had issues with 2.5.5 .. but I don't remember ...

@lock
Copy link

lock bot commented Aug 3, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants