php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41368 ADODB.Recordset ActiveConnection property - can't set with PHP 5.2.1+
Submitted: 2007-05-11 17:29 UTC Modified: 2020-02-08 14:06 UTC
Votes:17
Avg. Score:4.1 ± 1.3
Reproduced:13 of 14 (92.9%)
Same Version:5 (38.5%)
Same OS:9 (69.2%)
From: ben dot crum at colony101uk dot com Assigned:
Status: Verified Package: COM related
PHP Version: 5.2.2 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2007-05-11 17:29 UTC] ben dot crum at colony101uk dot com
Description:
------------
This seems similar to Bug #22162 - Program performs "illegal operation", but that was for PHP 4.3.1-dev.

I originally had PHP 5.1.6 installed on my PC and had written a few scripts using ADODB Connections and Recordsets.  These ran fine as web pages served by Apache's HTTP Server v2.0.

I upgraded to PHP 5.2.2 using the MSI and my scripts reported errors for the same line of code.


Overwriting the contents of my C:\PHP\ folder with the contents of the PHP 5.2.0 Zip file, I do NOT get these errors when running my scripts as web pages through Apache or from the command line (i.e. "php.exe c:\Web\simple.php").

If I overwrite the contents of my C:\PHP\ folder with the PHP 5.2.1 or 5.2.2 Zip files I get the error mentioned above when running them through Apache or from the command line.

Reproduce code:
---------------
Here is a simple sample that works with PHP 5.2.0, but breaks for me when using PHP 5.2.1+:

------------------------------
<?php

$rs = new COM('ADODB.Recordset');
// Problem line below for PHP 5.2.1+:
$rs->ActiveConnection = 'PROVIDER=SQLOLEDB; DATA SOURCE=(local); UID=sa; PWD=password; INITIAL CATALOG=myDB';
$rs->CursorLocation = 3;
$rs->Source = 'SELECT * FROM [myTable]';
$rs->Open();

if ( $rs->EoF )
{
	print( '- No records returned. -' );
}
else
{
	print( 'Returned records: ' . $rs->RecordCount );
}

$rs->Close();
$rs = NULL;

?>
------------------------------

Expected result:
----------------
This is the error I get on lines that set an ADODB.Recordset object's .ActiveConnection property:

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Provider<br/><b>Description:</b> Type mismatch.' in C:\Web\simple.php:4 Stack trace: #0 C:\Web\simple.php(4): unknown() #1 {main} thrown in C:\Web\simple.php on line 4

Actual result:
--------------
I don't think it's the objects and their properties coz this works as a VBScript (.vbs) file (no hissing please!):

------------------------------
OPTION EXPLICIT

DIM rs

SET rs = CreateObject("ADODB.Recordset")
rs.ActiveConnection = "PROVIDER=SQLOLEDB; DATA SOURCE=(local); UID=sa; PWD=password; INITIAL CATALOG=myDB"
rs.CursorLocation = 3
rs.Source = "SELECT * FROM [myTable]"
rs.Open

IF ( rs.EoF ) THEN
	WScript.Echo( "- No records returned. -" )
ELSE
	WScript.Echo( "Returned records: " & rs.RecordCount )
END IF

rs.Close
SET rs = Nothing
------------------------------


It looks to me that after 5.2.0, PHP no longer lets you set the .ActiveConnection of an ADODB.Recordset (or I've just messed up my PHP folder...).

Thanks for your help.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-15 08:33 UTC] jani@php.net
Assigned to the maintainer.
 [2008-01-08 13:27 UTC] pinkduck at dsl dot pipex dot com
This bug affects me too, the following code fails when trying to set the ActiveConnection back to null to allow a disconnected recordset.

// Connect to database
$dsn = "Provider=SQLNCLI;Server=localhost;UID=********;Pwd=*******";
$conn = new COM("ADODB.Connection");
$conn->ConnectionTimeout = CONNECTION_TIMEOUT_SECONDS;
$conn->CommandTimeout = COMMAND_TIMEOUT_SECONDS;
$conn->CursorLocation = adUseClient;
$conn->Open($dsn);

// Get recordset
$cmd->ActiveConnection = $conn;
$rs->Open($cmd);
// $rs->ActiveConnection = null; // PHP5 bug #41368
 [2008-11-07 14:53 UTC] anikushin at gmail dot com
I thing I'm expirionsing the same error but this is a connecton closed error, i think the connections drops with some microsoft gates. (unexpected error acured). hate VB with all junk from IT is any one will be reponsible for coding? 
Sorry, code (error)
===============================================
Connection OPEN.
Microsoft Access Driver: D:\ACCESS\DNSVER50.MDB
Execute: SELECT * FROM Customers WHERE CustNo = 22585;
Execute: INSERT INTO Customers ( CustName,CustAddress1,CustAddress2,CustCity,CustState,CustZip,CustTelephone,CustContact,Title,Notes,CustFaxNumber ) VALUES ( 'ADRIAN ANIKUSHIN','','XX XXXXXX STREET APP#1','MELROSE','MA','02176','1 (781) xxxxxxxx','ADRIAN ANIKUSHIN','','','1 (781) xxxxxxxx' );

Fatal error: Uncaught exception 'com_exception' with message 'Source: ADODB.Recordset
Description: Operation is not allowed when the object is closed.' in D:\WWW\dns\access_order.php:8
Stack trace:
#0 D:\WWW\dns\access_order.php(8): get_access_array()
#1 D:\WWW\dns\access_order.php(55): get_access_array('INSERT INTO Cus...')
#2 D:\WWW\dns\access_order.php(135): insert_access_array('Customers', Array)
#3 D:\WWW\dns\access_order.php(201): get_access_customer(Array, 'shipper')
#4 {main}
  thrown in D:\WWW\dns\access_order.php on line 8
 [2013-12-13 07:49 UTC] wez@php.net
-Status: Assigned +Status: Open -Assigned To: wez +Assigned To:
 [2020-02-08 14:06 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2020-02-08 14:06 UTC] cmb@php.net
This regression has been caused by the fix for bug #37588 (shipped
as of PHP 5.2.1), which causes `IDispatch_Invoke()` to be called
with `DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF` flags, albeit
the documentation[1] states (emphasis mine):

| The value MUST specify one and *only* *one* of the following bit
| flags: DISPATCH_METHOD, DISPATCH_PROPERTYGET,
| DISPATCH_PROPERTYPUT, or DISPATCH_PROPERTYPUTREF.

The ActiveConnection property supports two setters, namely

    [id(0x000003e9), propput, helpcontext(0x0012c90b)]
    void ActiveConnection([in] VARIANT rhs);

and

    [id(0x000003e9), propputref, helpcontext(0x0012c90b)]
    void ActiveConnection([in] IDispatch* rhs);

Apparently the second is preferred if both dispatch flags are
passed, so the type mismatch is to be expected.

[1] <https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-oaut/5c2a1997-60d7-496d-8d9a-ed940bbb82eb>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 13:01:27 2024 UTC