Question

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.

Was it helpful?

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!

OTHER TIPS

You aren't passing anything to table_exists. How is it supposed to know which table you are trying to check for? It takes one parameter...the table name you are checking for.

http://ellislab.com/codeigniter/user-guide/database/table_data.html

so, if you did this, and a table called "tablename" existed..then you would still get false, because table_exists returns TRUE if the table does exist.

if ($CI->db->table_exists('tablename')
{
return FALSE;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top