[wp-hackers] Plugin Questions

jill list at pericat.ca
Thu May 12 23:56:33 GMT 2005


Bill Smith wrote:

>1) I'm working on a small plugin that requires an additional database 
>table. Currently I'm using a query like
>
>SHOW TABLES LIKE 'wp_mytable'
>
>to check to see if my table already exists and create it if it doesn't. 
>That seems expensive to me to do everytime my plugin is loaded so I was 
>thinking about socking somthing away in wp_options that would let me 
>know that I've already created it.

The user might have need to truncate your table directly. This wouldn't reset
any option you'd set in another table.

>I'm assuming that by the time an 
>plugin code is executed that the options will have already been queried 
>and cached.
>
>What are others doing to accomplish this?

I pulled this from the online PHP manual:

function table_exists ($tablename, $db) {
  
   $result = mysql_list_tables($db);
   $rcount = mysql_num_rows($result);

   for ($i=0;$i<$rcount;$i++) {
       if (mysql_tablename($result, $i)==$tablename) return true;
   }
   return false;
}

jill
-- 
<http://pericat.ca/>


More information about the wp-hackers mailing list