1

I have one database in which all table names like below

configuration_dst,
developer_dst,
application_dst

Now I want to manage my query in which want to add database prefix after table name instead of before. For example :

{TABLE NAME}{PREFIX}

is it possible to manage using CI 3.0 ?

I have tried like below in Application/configuration/database.php

$db['default']['dbprefix']="_dst";
$db['default']['swap_pre']="{POST}";

Current Query :

$this->db->get('templates');

Current Table Name :

 tablename : _dsttemplates

Expected Table Name :

tablename : templates_dst

I need prefix after table Name not before but didn't get any solution.

8
  • above code is working.. Why you post this?? any error?? Commented Sep 17, 2015 at 4:43
  • this one is not working so just post here Commented Sep 17, 2015 at 4:47
  • $db['default']['swap_pre'] "{POST}"; should be $db['default']['swap_pre']="{POST}"; Commented Sep 17, 2015 at 4:48
  • sorry for forgot to add =(Equal sign) I want like below $this->db->get('developer') and prefix will add _mst so table name like developer_mst currently it is add prefix like _mstdeveloper and its not correct Commented Sep 17, 2015 at 4:50
  • $db['default']['swap_pre']=""; empty this Commented Sep 17, 2015 at 4:52

2 Answers 2

1

The only option is to change in driver files. You can do this using the following steps:

  1. Go to /system/database/DB_query_builder.php
  2. Search public function dbprefix
  3. Replace

    return $this->dbprefix.$table;
    

    with

    return $table.$this->dbprefix;
    

If it also interferes in any other places in your project then create a new function with replaced code like:

public function dbsuffix($table = '')
{
    if ($table === '')
    {
        $this->display_error('db_table_name_required');
    }

    return $table.$this->dbprefix;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Working with Database prefixes manually

if you use

$this->db->set_dbprefix('newprefix');
$this->db->dbprefix('tablename'); // outputs newprefix_tablename

its always gives the table name as

newprefix_tablename

Because this is Codeigniter pastern.

Codeigniter Prefix

4 Comments

I know this but i need tablename_prefix
so that you cant use Codeigniter dbprefix function.
How can i achieve this any help ?
@AnkitDoshi check this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.