请帮助我无法获取medoo中最后插入的ID
以下是我的代码:
<?php header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET,OPTIONS,POST,PUT,DELETE'); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); require 'vendor/autoload.php'; $app = new\Slim\Slim(); $app->container->singleton('db',function () use ($app) { return new medoo([ 'database_type' =>'pgsql', 'database_name' =>'emergency', 'server'=>'localhost', 'username' =>'postgres', 'password' => 'root', 'charset' => 'utf8', 'option' =>[ PDO::ATTR_CASE=>PDO::CASE_NATURAL ] ]); }); $app->db->post('/getinfo',function() { $body = $app->request->post(); $app->db->insert("emergencymessages", [ "message" =>$body["msg"], "createdby"=>$createdby ]); });
现在我想获得紧急消息表的最后一个插入ID如何 我明白了吗?
答案 0 :(得分:1)
根据文档(http://medoo.in/api/insert),db.mycollection.update(
{'_id': ObjectId("576b63d49d20504c1360f688")},
{ $pull: { "books" : { "title": "abc" } } },
false,
true
);
函数返回最后一个插入ID。
insert
编辑:
您可以尝试直接在medoo的$last_insert_id = $app->db->insert("emergencymessages", [
"message" =>$body["msg"],
"createdby"=>$createdby
]);
对象上调用lastInsertId();
:
pdo