exit;
}
// 在此处对数据库执行一些操作
// ...
// 现在完成,释放该连接
$dbh = null;
?>
计划在不久的将来为 PDO 增加连接缓存功能;就当前的 oci8 扩展而言,会重用与现有服务器的连接,并且在这些连接中,还会重用闲置的登录。当在缓存连接模式中运行时,如上面的代码段所示释放 $dbh 时会将该登录标记为可由其他连接重用。
如果您使用 ODBC 驱动程序访问 Oracle,则可能会很高兴地注意到,默认情况下 PDO_ODBC 驱动程序支持 ODBC 连接池。
使用 PDO
了解一个编程 API 的最好方式就是使用它,因此我们来看一下附带的这个演示,以了解如何进行批次更新(代码如下)。
<?php
// Create a PDO database handle object
// the 'oci:' string specifies that the OCI driver should be used
// you could use 'oci:dbname=name' to specify the database name.
// The second and third parameters are the username and password respectively
$dbh = new PDO('oci:', 'scott', 'tiger');
// Create a test table to hold the data from credits.csv
$dbh->exec("
CREATE TABLE CREDITS (
extension varchar(255),
name varchar(255)
)");
// start a transaction
$dbh->beginTransaction();
// prepare to insert a large quantitiy of data
$stmt = $dbh->prepare("INSERT INTO CREDITS (extension, name) VALUES (:extension, :name)");
// bind the inputs to php variables; specify that the data will be strings
// with a maximum length of 64 characters
$stmt->bindParam(':extension', $extension, PDO_PARAM_STR, 64);
$stmt->bindParam(':name', $name, PDO_PARAM_STR, 64);
// Open the .csv file for import
$fp = fopen('credits.csv', 'r');
while (!feof($fp)) {
list($extension,
| 对此文章发表了评论 |
