我创建了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
在此功能结束时仍然打开,那么如何关闭它?
答案 0 :(得分:4)
来自文档:
当请求结束时,Phalcon会自动关闭并销毁活动连接。
如果您确实需要在此之前关闭连接,则PdoAdapter应提供close()
方法。