Skip to content

php_com_dotnet - can not create VT_ERROR variant type #8750

Closed
@systoolz

Description

@systoolz

Description

Can not create VT_ERROR variant type. It's required for some COM method calls where you need to specify an empty argument, since it's VT_ERROR type variant with error DISP_E_PARAMNOTFOUND (0x80020004) as actual error code (see here).

The following code:

<?php // database.php
  // next line works only in PHP 4.4.9 (PHP 5, 6, 7 and 8 are bugged)
  $vtMissing = new VARIANT(0x80020004, VT_ERROR);
  $db = new COM('ADODB.Connection');
  $db->ConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb';
  $db->Mode = 1; // adModeRead
  $db->Open();
  // adSchemaProviderSpecific, *missing*, JET_SCHEMA_USERROSTER
  $rs = $db->OpenSchema(-1, $vtMissing, '{947bb102-5d43-11d1-bdbf-00c04fb92675}');
  // manual counting since rs.RecordCount is -1 (not supported)
  $i = 0;
  while (!$rs->EOF) {
    $rs->MoveNext();
    $i++;
  }
  $rs->Close();
  $rs = null;
  $db->Close();
  $db = null;

  echo $i;

Resulted in this output:

Fatal error: Uncaught com_exception: Variant type conversion failed: Type mismatch in Z:\database.php:3
Stack trace:
#0 Z:\database.php(3): variant->__construct(2147614724, 10)
#1 {main}
  thrown in Z:\database.php on line 3

But I expected this output instead:

1

Test file "database.mdb" can be any Microsoft Access database file, even without any tables inside.
More details can be found in this article (auto-translated from Russian):
VT_MISSING argument in PHP for COM objects

PHP Version

PHP 8.1.7 x64

Operating System

Windows 7 x64

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions