how to create a TEMPORARY table in laravel, insert a record and retrieve hello, I'm trying to create a temp table in laravel and insert a record and retrieve that record from temp table and then drop the table.
But my temp table is not created
DB::raw(“CREATE TEMPORARY TABLE tbl_temp(temp_id VARCHAR(100),tempcolumn1 VARCHAR(100),tempcolumn2 VARCHAR(100),tempcolumn3 VARCHAR(100)) ;
                Try this
// CREATE TEMPORARY TABLE
$productList = DB::insert( DB::raw( "CREATE TEMPORARY TABLE tempproducts") );
// DELETE TEMPORARY TABLE
$dropTable = DB::unprepared( DB::raw( "DROP TEMPORARY TABLE tempproducts" ) );
                        I have recently created a temp table( laravel 8) as such:
public function createLocalStoreProductTable(): \Illuminate\Http\JsonResponse
    {
        $tempTable = env("DB_TEMP_STORE_PRODUCT_TABLE_NAME");
        DB::connection('mysql')->statement(
            "CREATE TABLE " . $tempTable . " (
                    `uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
                    `store_uid` int(10) unsigned NOT NULL)
                     PRIMARY KEY (`uid`),
                     KEY `store_uid` (`store_uid`)
                     ) ENGINE=InnoDB AUTO_INCREMENT=3035849 DEFAULT 
                       CHARSET=utf8;"
 return response()->json(array('success' => true), Response::HTTP_OK);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With