Can I create and share a connection between PDO and mysql_ functions
No, such a feature is not available with PHP.
or anything more efficient?
Sure. The efficient way is to program against interfaces. The Zebra_Mptt
library should define an interface for the database adapter it uses so that you can replace it with one that is re-using your database connection.
As it currently doesn't, you would need to refactor it, encapsulate the database interaction calls into the standard database connection object for that library, then extract the interface of that connection object and then create your PDO variant and inject it instead.
I just took a brief look, the class is rather straight forward so this should be merely straight forward. All it does is firering some SQL queries and in the very beginning checking if the database is online which you can easily map and defer.
In case you don't want to do that, you can take a pre-existing wrapper for the mysql_*
interface, either replace the prefix in the existing library or just disable the mysql extension and then let it create the functions based on PDO. Such a wrapper is here:
Usage:
<?php
require('/path/to/mysqlpdo.php');
mysqlpdo::createfunctions('mysql');
It will need an additional mysql_ping()
and mysql_real_escape_string()
wrapped to have it work though, but this should be easily feasibile, but nothing is perfect in that field.