如何关闭 phalcon 数据库连接?
How to close a phalcon database connection?
我创建了一个 connection
以插入数据和 return 最后插入的自动增量列的 id :
function add($tab) {
$champs= "";
$value = "";
$separateur ="";
$tab["commande_date"] = convertDateFormat5($tab["commande_date"]);
foreach ($tab as $k => $v){
if ($k == "salle_code" || $k == "table_code")
continue;
$champs .= $separateur . $k;
$value .= $separateur . "'" . $v . "'";
$separateur = ",";
}
$champs = '('.$champs.')';
$value = '('.$value.')';
$sSQL = "INSERT INTO Commande $champs VALUES $value";
$config = array(
"host" => "localhost",
"dbname" => BDD,
"port" => 3306,
"username" => "root",
"password" => ""
);
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql($config);
$success = $connection->execute($sSQL);
$id = $connection->lastInsertId();
return $id;
}
这个函数结束时connection
还是打开的,怎么关闭呢?
来自文档:
Phalcon automatically closes and destroys active connections when the request ends.
如果您确实需要在此之前关闭连接,您的 PdoAdapter 应该提供一个 close()
方法。
我创建了一个 connection
以插入数据和 return 最后插入的自动增量列的 id :
function add($tab) {
$champs= "";
$value = "";
$separateur ="";
$tab["commande_date"] = convertDateFormat5($tab["commande_date"]);
foreach ($tab as $k => $v){
if ($k == "salle_code" || $k == "table_code")
continue;
$champs .= $separateur . $k;
$value .= $separateur . "'" . $v . "'";
$separateur = ",";
}
$champs = '('.$champs.')';
$value = '('.$value.')';
$sSQL = "INSERT INTO Commande $champs VALUES $value";
$config = array(
"host" => "localhost",
"dbname" => BDD,
"port" => 3306,
"username" => "root",
"password" => ""
);
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql($config);
$success = $connection->execute($sSQL);
$id = $connection->lastInsertId();
return $id;
}
这个函数结束时connection
还是打开的,怎么关闭呢?
来自文档:
Phalcon automatically closes and destroys active connections when the request ends.
如果您确实需要在此之前关闭连接,您的 PdoAdapter 应该提供一个 close()
方法。