How to create table in php myadmin from codeigniter 4 controller

Step 1 Create a controller and a function.Here we have create a controller name MyController and function name is index for demo.
<?php namespace App\Controllers;
 
use CodeIgniter\Controller;

class MyController extends Controller{

    public function index(){    

}

}
Step 2 paste the below code for connect database inside the index method.
	$forge = \Config\Database::forge();
By the above line your controller will get connected to default database.

Step 3 Now add the columns you want to define in your database like below.
$forge->addField('id');
        $forge->addField([
'Name' => ['type' => 'varchar', 'constraint' => 200],
'shop'    => ['type' => 'varchar', 'constraint' => 200],
'install_date' => ['type' => 'datetime', 'null' => true],

            
   ]);

In the above code addField function is use to add column in database,
then here ‘Name’,’shop’ and ‘install_date’ are the name of columns and type define the type of column that what type of data they will store.
You can add any number of columns in database according to your requirement.

How to create table in php myadmin from codeigniter 4 controllerexpoundsofttechsolution


How to create a table in PHP my admin from Codeigniter 4 controller