如何从 Doctrine\DBAL\Connection 获取 php-native handle?
How to get php-native handle from Doctrine\DBAL\Connection?
给定代码
$connectionParams = array(
'dbname' => $this->dbname,
'user' => $this->dbuser,
'password' => $this->dbpass,
'host' => $this->dbhost,
'driver' => 'mysqli',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
var_dump($conn);
如何从 $conn(Doctrine\DBAL\Connection)获取底层的 mysqli 句柄?
我找到了*一种方法*来访问它,但它显然不是它应该完成的方式,所以我愿意提出建议:
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
foreach((array)$conn->getWrappedConnection() as $mysqli){
// TODO: find official way of getting the handle.
// here we are casting it to (array) to access its PRIVATE PROPERTIES
// it's a fugly hack.
break;
}
var_dump($mysqli);
您可以这样获取:
$mysqli = $conn->getWrappedConnection()->getWrappedResourceHandle();
给定代码
$connectionParams = array(
'dbname' => $this->dbname,
'user' => $this->dbuser,
'password' => $this->dbpass,
'host' => $this->dbhost,
'driver' => 'mysqli',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
var_dump($conn);
如何从 $conn(Doctrine\DBAL\Connection)获取底层的 mysqli 句柄?
我找到了*一种方法*来访问它,但它显然不是它应该完成的方式,所以我愿意提出建议:
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
foreach((array)$conn->getWrappedConnection() as $mysqli){
// TODO: find official way of getting the handle.
// here we are casting it to (array) to access its PRIVATE PROPERTIES
// it's a fugly hack.
break;
}
var_dump($mysqli);
您可以这样获取:
$mysqli = $conn->getWrappedConnection()->getWrappedResourceHandle();