how to use "if exists" - INSERT INTO IF EXISTS tMyTable ???

This is a discussion on how to use "if exists" - INSERT INTO IF EXISTS tMyTable ??? within the PHP Language forums, part of the PHP Programming Forums category; Google can't find me a good example of how to use the "if exists" syntax in MySql. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-02-2004
lawrence
 
Posts: n/a
Default how to use "if exists" - INSERT INTO IF EXISTS tMyTable ???

Google can't find me a good example of how to use the "if exists"
syntax in MySql. Is it right that to use it this way:

INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")


I want to insert into a table but only if the table exists.

How does one, in general, from PHP, test for the existence of a table,
without getting an error message?
Reply With Quote
  #2 (permalink)  
Old 09-02-2004
Alvaro G. Vicario
 
Posts: n/a
Default Re: how to use "if exists" - INSERT INTO IF EXISTS tMyTable ???

*** lawrence escribió/wrote (2 Sep 2004 10:05:00 -0700):
> Google can't find me a good example of how to use the "if exists"
> syntax in MySql. Is it right that to use it this way:
>
> INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")


As far as I know, it's CREATE TABLE the one that accepts a similar syntax:

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
[table_options] [select_statement]


"INSERT inserts new rows into an existing table"

http://dev.mysql.com/doc/mysql/en/INSERT.html


> How does one, in general, from PHP, test for the existence of a table,
> without getting an error message?


You can use mysql_list_tables() and search in the result.


--
--
-+ Álvaro G. Vicario - Burgos, Spain - ICQ 46788716
+- http://www.demogracia.com (la web de humor para mayores de 100 años)
++ «Sonríe, que te vamos a hacer una foto para la esquela»
--
Reply With Quote
  #3 (permalink)  
Old 09-02-2004
Westcoast Sheri
 
Posts: n/a
Default Re: how to use "if exists" - INSERT INTO IF EXISTS tMyTable ???

lawrence wrote:

> Google can't find me a good example of how to use the "if exists"
> syntax in MySql. Is it right that to use it this way:
>
> INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")
>
> I want to insert into a table but only if the table exists.
>
> How does one, in general, from PHP, test for the existence of a table,
> without getting an error message?


I don't know....but in a php script when I put the "@" symbol before a
mysql query, it seems to supress errors...
$blah = @mysql_query("insert something into my table values etc");

Reply With Quote
  #4 (permalink)  
Old 09-02-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: how to use "if exists" - INSERT INTO IF EXISTS tMyTable ???

In article <41376447.DDA56BED@nospamun8nospam.com>, Westcoast Sheri wrote:
> lawrence wrote:
>
>> Google can't find me a good example of how to use the "if exists"
>> syntax in MySql. Is it right that to use it this way:
>>
>> INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")
>>
>> I want to insert into a table but only if the table exists.
>>
>> How does one, in general, from PHP, test for the existence of a table,
>> without getting an error message?

>
> I don't know....but in a php script when I put the "@" symbol before a
> mysql query, it seems to supress errors...
> $blah = @mysql_query("insert something into my table values etc");


Offcourse is it much nicer not the get the error in the first place.
And error handling (also hiding warnings) is explained in detail in the
manual ;)

--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Reply With Quote
  #5 (permalink)  
Old 09-23-2004
lawrence
 
Posts: n/a
Default Re: how to use "if exists" - INSERT INTO IF EXISTS tMyTable ???

"Alvaro G. Vicario" <kAlvaroNOSPAMTHANKS@terra.es> wrote in message news:<3qolqle953nf$.1c9ekrqu0rvfj.dlg@40tude.net>. ..
> *** lawrence escribió/wrote (2 Sep 2004 10:05:00 -0700):
> > Google can't find me a good example of how to use the "if exists"
> > syntax in MySql. Is it right that to use it this way:
> >
> > INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")

>
> As far as I know, it's CREATE TABLE the one that accepts a similar syntax:
>
> CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
> [table_options] [select_statement]


SELECT statements also all the use of EXISTS:

http://dev.mysql.com/doc/mysql/en/EX...ubqueries.html

I wish I knew where to go for definitive answers. The MySql manual
leaves a great deal unanswered. It doesn't say, for instance, that
EXISTS cannot be used with INSERT, so I guess I'll have to experiment.
But if I get a syntax error, I won't know if it is because INSERT
doesn't allow EXISTS, or it does but I wrote it wrong.







> > How does one, in general, from PHP, test for the existence of a table,
> > without getting an error message?

>
> You can use mysql_list_tables() and search in the result.


This is a good way to go then. EXISTS is less than useful if I can't
get the info I need about it. Might as well rely on PHP to do all my
testing for me. PHP is much better documented than MySql, anyway,
which makes it easier to experiment with.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:06 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0