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. ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
*** 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» -- |
|
|||
|
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"); |
|
|||
|
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> |
|
|||
|
"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. |