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.
- 2. Field MetaData.
- 3. Retrieve Field Metadata.
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.
- Name : Column name
- max_length : maximum length of the column
- primary_key : 1 if the column is a primary key
- type : the type of the column
Output will be like this:-
Advertisements
Add Comment
📖 Read More
- 1. Codeigniter Custom Function Calls
- 2. Codeigniter Database Caching Class
- 3. Codeigniter DB Driver Reference