Search code examples
codeigniteractiverecordpyrocms

issue tabel_exist in pyrocms


i am using pyrocms for my web application.
i want create library for my module in addons.
when i use this code for tabel llist in my database.

$CI = & get_instance();
$all=$CI->db->list_tables();

i have "defualt_products" value in $all array. this means i have "default_products" table in my database. but when i use next code , result is false. why?

if(!$CI->db->table_exists("default_products"))
    return false;

i use pyrocms 2.2.


Solution

  • You can use the dbprefix method to include you table prefix from database.php config file:

    if ( !$CI->db->table_exists($CI->db->dbprefix('products')) ){
       //there is no such table, products
       echo "there is no table named ".$CI->db->dbprefix('products');
       die();
    }else{
       //table found
       echo "table found"; die();
    }
    

    In case it dose not work, then I think your problem is not this piece of code!