Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 4 - Temporary tables
#1

(This post was last modified: 10-10-2022, 08:02 PM by paulbalandan.)

Hi, guys!
Sometimes we need temporary tables to get a complex table created by code in CI4.

Let's do it simple.

$this->forge = \Config\Database::forge('default'); // see CI4 guide

//If table already exists, let's drop it
$this->forge->dropTable('my_temporary_table', true); // use any name you want

//Adding fileds
$this->forge->addField('id  MEDIUMINT NOT NULL AUTO_INCREMENT');
$this->forge->addField('name VARCHAR(30)');

//Add primary key
$this->forge->addKey('id',true);

Pay attention! Here's the secret!
$this->forge->createTable('my_temporary_table',false,['TEMPORARY TABLE']);

For any additional help and sintax go to
https://codeigniter.com/user_guide/dbmgmt/forge.html
Reply
#2

MySQLTUTORIAL - MySQL Temporary Table
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB