Tutorialsplane

Codeigniter Database Metadata Reference


Codeigniter Database Metadata Reference – This database reference provides many functions that are used to fetching table information from the database. Here in this tutorial, we are going to explain how to use Database Metadata Reference.


Codeigniter Database Metadata Reference | Example.

Let us understand how Database Metadata Reference works in codeigniter with examples.

Functions:-

There are following functions available in Database Metadata reference. Now we will explain one by one.

1. Table MetaData.

Here is simple demo of table metaData.

Example:-

Syntax of table metaData.

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class MetaData_controller extends CI_Controller 
{
public function table_list()
{
$tables = $this-?>db->list_tables();
foreach ($tables as $table)
{
echo $table;
echo "<br/>";
}
}
}
?>

Output will be like this:-

2. Field MetaData.

Here is simple demo of field metaData.

Example:-

Syntax of field metaData.

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class MetaData_controller extends CI_Controller 
{
public function field_data()
{
$fields = $this-?>db->list_fields('blog');
foreach ($fields as $field)
{
echo $field;
}		
}
}
?>

Output will be like this:-

3. Retrieve Field Metadata.

Here is simple demo of retrieve field metadata.

Example:-

Syntax of retrieve field metadata.

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class MetaData_controller extends CI_Controller 
{
public function field_Metadata()
{
$fields = $this-?>db->field_data('blog');
foreach ($fields as $field)
{
echo $field->name;
echo $field->type;
echo $field->max_length;
echo $field->primary_key;
}		
}
}
?>

The following data is available from this function if supported by your database.

Output will be like this:-

Models

Connect Database

Helpers

Libraries

Helper Reference

Library Reference

Database Reference