Re: Is there a way to find out if a table exists?

2003-09-19 Thread Paul DuBois
At 3:37 PM -0500 9/19/03, Don Read wrote:
On 19-Sep-2003 Don Read wrote:
 On 19-Sep-2003 Dan Anderson wrote:
 I am trying to make my PHP script autodetect when a table in a mySQL
 database exists, and when it doesn't, create it. 

 

 function tableexists($tbl) {
 $res = @mysql_query("SELECT 1 FROM $tbl");
 return ($res ? true : false);
 }
Err ... make that

 $res = @mysql_query("SELECT 1 FROM $tbl LIMIT 1");
Better yet, SELECT 1 FROM $tbl WHERE 1 = 0, which returns even
fewer rows. :-)
Or use SHOW TABLES LIKE 'name of table here' or
SHOW TABLE STATUS LIKE 'name of table here' and see if you
get any row back.
--
Paul DuBois, Senior Technical Writer
Madison, Wisconsin, USA
MySQL AB, www.mysql.com
Are you MySQL certified?  http://www.mysql.com/certification/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]


Re: Is there a way to find out if a table exists?

2003-09-19 Thread Don Read

On 19-Sep-2003 Don Read wrote:
> 
> On 19-Sep-2003 Dan Anderson wrote:
>> I am trying to make my PHP script autodetect when a table in a mySQL
>> database exists, and when it doesn't, create it.  
>> 
> 
> 
> function tableexists($tbl) {
> $res = @mysql_query("SELECT 1 FROM $tbl");
> return ($res ? true : false);
> }
> 

Err ... make that 

 $res = @mysql_query("SELECT 1 FROM $tbl LIMIT 1");


-- 
Don Read [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.
(53kr33t w0rdz: sql table query)


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Is there a way to find out if a table exists?

2003-09-19 Thread Don Read

On 19-Sep-2003 Dan Anderson wrote:
> I am trying to make my PHP script autodetect when a table in a mySQL
> database exists, and when it doesn't, create it.  
> 


function tableexists($tbl) {
$res = @mysql_query("SELECT 1 FROM $tbl");
return ($res ? true : false);
}


Regards,
-- 
Don Read [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.
(53kr33t w0rdz: sql table query)


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



RE: Is there a way to find out if a table exists?

2003-09-19 Thread Jennifer Goodie
> Is there some way to do something like:
> 
> SELECT * FROM tables WHERE name = "table_name";
> 
> And get a result I could test for truth, and thus run my script?

Show tables like 'table_name';

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Is there a way to find out if a table exists?

2003-09-19 Thread Roger Baklund
* Dan Anderson
> I am trying to make my PHP script autodetect when a table in a mySQL
> database exists, and when it doesn't, create it.
>
> Is there some way to do something like:
>
> SELECT * FROM tables WHERE name = "table_name";
>
> And get a result I could test for truth, and thus run my script?

SHOW TABLES LIKE "table\_name";

Note that the underscore must be escaped with a backslash, because the LIKE
operator use underscore as a wildcard for a single character. In other
words, this statement:

SHOW TABLES LIKE "table_name";

... would match "table_name", but also "tableAname" and tableBname".

--
Roger


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Is there a way to find out if a table exists?

2003-09-19 Thread Dan Anderson
I am trying to make my PHP script autodetect when a table in a mySQL
database exists, and when it doesn't, create it.  

Is there some way to do something like:

SELECT * FROM tables WHERE name = "table_name";

And get a result I could test for truth, and thus run my script?

Thanks in advance,

Dan


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]