1

I have been using PyroCMS and CI for quite some time, and truly love it.

I am extending a DB module that will allow an admin user to manage a DB without having to use something like phpMyAdmin.

The only thing I have been able to get working however is Browsing a table's field values (i.e 'SELECT * FROM 'table_name').

I want to include more functions, but I can't seem to get dbforge to work properly. I know it is loaded because dbforge is used to uninstall modules. I also get no error when calling functions from it.

Here is an example of my code from the controller (dbforge has already been loaded).

public function drop($table_name)
{
    $table_name = $this->uri->segment(4);
    $this->dbforge->drop_table($table_name);
    redirect('admin/database/tables');
}

Lets say the function gets called from this url:

.../admin/database/drop/table_name

It appears to work... but instead it just redirects to the tables overview.

Is there something I am missing? Shouldn't [$this->dbforge->drop_table($table_name);] always drop a table (given $table_name is valid)?

EDIT

As a work around, I was able to use:

public function drop($table_name)
{
    $table_name = $this->uri->segment(4);
    //$this->dbforge->drop_table($table_name);
    $this->db->query("DROP TABLE ".$table_name);
    redirect('admin/database/tables');
    return TRUE;
}

I really would like to use DB forge, however...

jiminikiz
  • 2,867
  • 1
  • 25
  • 28
  • Could you specify whether the answers provided by other users were helpful? From our assessment, it seems that the problem is unrelated to the functionality of our product. Please refer to the documentation below: https://codeigniter.com/userguide3/database/index.html If the issue still persists, please fill out the form below. Provide us with a detailed description of the problem and the actions you have taken. Also, attach relevant screenshots to aid us in better understanding the issue. https://www.devart.com/company/contactform.html Our specialists will examine this issue thoroughly. – Devart May 10 '23 at 07:45
  • The accepted answer below posted by [@phil](https://stackoverflow.com/users/124378/phil-sturgeon) and my reply comment provide more context into the issue I was having as well as reveals my misunderstanding at the time of this post. Many things have changed these last dozen years... – jiminikiz May 12 '23 at 16:19

1 Answers1

2

I think you might be getting a little confused by the site prefixes in PyroCMS 1.3.x.

By default all installations of Community and Professional will have default_ as a prefix for all tables in the first site. If you have Professional you can add new sites and the site reference will be whatever_ instead of default_

This prefix is accounted for by dbforge, so when you want to delete default_blog you would just delete:

/admin/database/drop/blog

Also, why are you accepting the $table_name as an argument then overriding it with a uri segment?

Also, why are you accepting the $table_name as an argument then overriding it with a uri segment?

See what I did there? xD

public function drop($table_name)
{
    $this->dbforge->drop_table($table_name);
    redirect('admin/database/tables');
}
Phil Sturgeon
  • 30,637
  • 12
  • 78
  • 117
  • Yeah, it is useless to override the table variable with the 4th uri segment when it is already passed in as a parameter. This was posted a while ago, so I totally get a noob card for that >. – jiminikiz Jan 15 '12 at 20:33