php - 在 laravel/lumen 中创建临时表并插入数据

标签 php mysql laravel lumen

我想在 Laravel/Lumen 中创建临时表,我制作了这样的架构。

Schema::create('temp_image', function (Blueprint $table) {
    $table->increments('id');
    $table->string('link');
    $table->timestamps();
    $table->temporary();
});

当我运行 php artisan migrate 时,我看到...

Migrating: 2017_11_25_165640_create_temp_table
Migrated:  2017_11_25_165640_create_temp_table

...但它没有创建任何表。发生了什么?

最佳答案

临时表是基于 session 的。它不是在 SQL Server 上创建的。您可以查看this laracast 中的文章。

临时表也可以在lumen中使用。我们可以使用架构生成器 创建表和删除表。 假设我们有一个用于简单请求的函数。我们可以使用临时表,如下所示-

public function temporary_check()
{
    Schema::create('temp_message', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('sender_id');
        $table->integer('receiver_id');
        $table->string('message');
        $table->timestamps();
        $table->temporary();
    });

    DB::table('temp_message')->insert(['sender_id'=>2,'receiver_id'=>3,'message'=>'message temp check']);

    $data = DB::table('temp_message')->get();

    Schema::drop('temp_message');

    return $data;
}

由于临时表是基于 session 的,因此您应该始终通过删除来释放 内存 工作结束时的表格。

关于php - 在 laravel/lumen 中创建临时表并插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47493155/

相关文章:

python - 如何在 Django 模型查询中从 mysql 数据库中获取日期时间作为字符串

php - Laravel 使用管道从 Redis 集访问数据

php - SQLSTATE[HY000] [2005] 未知的 MySQL 服务器主机 'localhost:3306' (2)

php - Ion 编码不适用于 php post

php - 来自同一数组的不同链接?

php - 如果未重定向,则重定向页面

php - 按其他表中的标题对结果进行分组

php - 安装时设备上的同一应用程序显示两个图标

mysql select查询不返回任何内容

Laravel mix 在 mix v4+ 中总是未定义