【发布时间】:2015-09-24 07:23:10
【问题描述】:
我创建了一个connection 来插入数据并返回最后插入的自动增量列的 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在这个函数结束时仍然是打开的,那么如何关闭它呢?
【问题讨论】:
-
$connection->close(); ?