我创建了一个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;
}
Run Code Online (Sandbox Code Playgroud)
在connection今天仍然是一个功能月底开放,因此如何关闭它?