Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a complete list of all methods from a specific PDO driver object?

I was trying to get all methods for each PDO driver (I have all of them installed on my Windows PC).

But if I try, for example, using Postgres (pdo_pgsql):

var_export(get_class_methods('PDO'));

The result is:

array (
  0 => '__construct',
  1 => 'prepare',
  2 => 'beginTransaction',
  3 => 'commit',
  4 => 'rollBack',
  5 => 'inTransaction',
  6 => 'setAttribute',
  7 => 'exec',
  8 => 'query',
  9 => 'lastInsertId',
  10 => 'errorCode',
  11 => 'errorInfo',
  12 => 'getAttribute',
  13 => 'quote',
  14 => '__wakeup',
  15 => '__sleep',
  16 => 'getAvailableDrivers',
)

But this list is incomplete because PDO Postgres includes methods like:

$pdo->pgsqlCopyToArray('my_table');

Is there a way to get all methods and not only the PDO defaults only?

Thanks in advance, Celso

Edit:

I've tried Reflection too, and the result is incomplete like get_class_methods():

var_export(array_column((new ReflectionClass('PDO'))->getMethods(), 'name'));

The result is the same:

array (
  0 => '__construct',
  1 => 'prepare',
  2 => 'beginTransaction',
  3 => 'commit',
  4 => 'rollBack',
  5 => 'inTransaction',
  6 => 'setAttribute',
  7 => 'exec',
  8 => 'query',
  9 => 'lastInsertId',
  10 => 'errorCode',
  11 => 'errorInfo',
  12 => 'getAttribute',
  13 => 'quote',
  14 => '__wakeup',
  15 => '__sleep',
  16 => 'getAvailableDrivers',
)
like image 1000
celsowm Avatar asked Jun 01 '19 04:06

celsowm


1 Answers

First of all you have to understand what is PDO according to PHP Docs it states:

Introduction ¶

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.

PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0; PDO requires the new OO features in the core of PHP 5, and so will not run with earlier versions of PHP.

It clearly states that PDO is lightweight interface for accessing database. Look at note provided there reproduced again

Note: that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

To understand more clearly there are four things in the POD i.e.

PDO Interface            PDO Statements            PDO Exceptions            PDO Drivers

(Same for All DB's)    (Same for All DB's)        (Same for All DB's)        (Differ for All DB's)

get_class_methods only list the Methods of PDO and not other methods of Statement Functions, Exceptions functions and Driver Functions

Now think there are four different classes for PDO as:

Class PDO         Class PDO_Statement        Class PDO_Exections        Class PDO_Driver

Statements, Exception and Drivers are internally linked to PDO Class

Now you are calling get_class_methods on Class PDO it will show the Methods of Class PDO and if you want to know the all the Methods of PDO_Driver then you have to call correct name of PDO_Driver class.

Now what is the correct name of PGSQL Driver it is the internals of PHP and for that you have to study PHP internals.

like image 170
Vineet1982 Avatar answered Nov 19 '22 08:11

Vineet1982