Search code examples
oracle-databasepdointrospectiondatabase-metadata

How emulate PDO::getColumnData() using Oracle?


I have a vanilla PHP 7 app that (aims to) suports MySQL, Postgres, SQL Server and Oracle.

I've faced a problem now because all but Oracle (pdo_oci), supports getColumnData()

$statement   = $pdo->query('SELECT titulo, preco FROM livro');
$metadados   = $statement->getColumnMeta(0);

MySQL:

array(7) { ["native_type"]=> string(10) "VAR_STRING" ["pdo_type"]=> int(2) ["flags"]=> array(1) { [0]=> string(8) "not_null" } ["table"]=> string(5) "livro" ["name"]=> string(6) "titulo" ["len"]=> int(765) ["precision"]=> int(0) } 

Postgres:

array(8) { ["pgsql:oid"]=> int(1043) ["pgsql:table_oid"]=> int(16585) ["table"]=> string(5) "livro" ["native_type"]=> string(7) "varchar" ["name"]=> string(6) "titulo" ["len"]=> int(-1) ["precision"]=> int(259) ["pdo_type"]=> int(2) } 

SQLServer:

array(8) { ["flags"]=> int(0) ["sqlsrv:decl_type"]=> string(7) "varchar" ["native_type"]=> string(6) "string" ["table"]=> string(0) "" ["pdo_type"]=> int(2) ["name"]=> string(6) "titulo" ["len"]=> int(255) ["precision"]=> int(0) }

Is there an way to emulate a similar result from the others drivers but using pdo_oci?


Solution

  • PHP 7.4 adds support to PDO_OCI for this: bugs.php.net/bug.php?id=76908