2017-03-02 907 views
0

如何在laravel中創建TEMPORARY表,插入記錄並檢索 hello,我試圖在laravel中創建臨時表,並插入記錄並從臨時表中檢索該記錄,然後放下桌子。如何在laravel中創建TEMPORARY表

,但我的臨時表不創建

DB::raw(「CREATE TEMPORARY TABLE tbl_temp(temp_id VARCHAR(100),tempcolumn1 VARCHAR(100),tempcolumn2 VARCHAR(100),tempcolumn3 VARCHAR(100)) ; 

回答

0

用模式您可以創建臨時表...

Schema::create('temp', function (Blueprint $table) { 
       $table->increments('id'); 
       $table->string('session_id'); 

      }); 
+2

可以使用[temporary()](https://laravel.com/api/5.4/Illuminate/Database/Schema/Blueprint.html#method_temporary)方法:'$ table-> temporary();'... –

1

試試這個

//創建臨時表

$productList = DB::insert(DB::raw("CREATE TEMPORARY TABLE tempproducts")); 

//刪除臨時表

$dropTable = DB::unprepared(DB::raw("DROP TEMPORARY TABLE tempproducts")); 
+0

@ abbas-ahmad這是否解決了您的問題? – Manish