How to get connection resource from PDO object?

I need to get a connection resource from an existing PDO. For example:

... $oPDO = new PDO($sOdbcDsn); $rOdbcConnection = $oPDO -> getConnection(); odbc_prepare($rOdbcConnection, $sQuery); ... 

Conversely, I would like to transfer an existing connection to the PDO constructor. I want to be able to work with PDOs and direct connections separately.

Is there a way to extract a compound from PDO?

+7
source share
1 answer

I think you have two options:

  • wrap the PDO connection (and methods) in a class that you can pass as you want. Define a copy constructor that will reuse the connection descriptor.

  • pump the source into the PDO object from the PHP source and create what you need.

+2
source

All Articles