At 06:20 AM 3/28/2002, you wrote:
>On 27-Mar-2002 Ken Anderson wrote:
> >
> >
> >
> >
> >
> > What is the fastest way to check if a table exists?
> > Do a select and catch the error?
> > Try to create the table, and catch the error?
> > Other options?
> > Thanks,
> > Ken
>
>Yes, in php:
>
>function tableexists($tbl) {
> $res = @mysql_query( "SELECT count(*) FROM $tbl");
> return ($res ? true : false);
>}
Don,
There may be a way to improve your function. Change the select
statement to "Select 1 from $tbl LIMIT 1". Because some table types like
InnoDb will physically count the rows in the table and can take several
seconds or even minutes. Selecting a constant is extremely fast especially
with the LIMIT of 1. If the table doesn't exist you get an error. Works for
me. ;-)
Brent
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php