Fetch database meta data in codeigniter 4 - deesoft service

Fetch database meta data in codeigniter 4

Deepak Tailor Image
Deepak Tailor - Dec 01 2020
Fetch database meta data in codeigniter 4

Which tables are we using in the metadata database? And what are the names of the columns in the table. Etc. We can check.

Tables List in our connected database

To list the tables, we use the listTables function. This function returns the array of the table name.

public function table_list()
{
	// $this->seller database connection
	
	$query = $this->seller->listTables();
	echo "<pre>";
	print_r($query);
}
Check table exist in database

We can check with tableExists function whether a table exists in the database. It returns true or false.

public function table_exists()
{
	$query = $this->seller->tableExists('users');
	if($query == true){
		echo "Table Exist";
	}
	else{
		echo "Table Not Exist";
	}
}
Fetch fields list in table

With the getFieldNames function, we can fetch the column names of any table.

public function table_fields()
{
	$query = $this->seller->getFieldNames('users');
	echo "<pre>";
	print_r($query);
}
Check field name exist in table

Use the fieldExist function to check the field names in the table.

public function field_exist()
{
	$query = $this->seller->fieldExists('salary','users');
	if($query == true){
		echo "Field Exist";
	}
	else{
		echo "Field Not Exist";
	}
}
Fetch fields metadata

To get the field's meta data, we use the getFieldData function. From this we can find column name, type, maximum length, primary key etc.

public function field_data()
{
	$query = $this->seller->getFieldData('users');
	echo "<pre>";
	print_r($query);
}
Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in