473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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?
Jul 17 '05 #1
4 11096
*** 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»
--
Jul 17 '05 #2
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");

Jul 17 '05 #3
In article <41***************@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>
Jul 17 '05 #4
"Alvaro G. Vicario" <kA*****************@terra.es> wrote in message news:<3q*****************************@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.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: LRW | last post by:
I'm not exactly sure how to even ask the question, and I know my terminology is not good as I'm a SQL beginner, but, here goes. I need to find a way to make an if statement within an array...or,...
5
by: Jason Charalambides | last post by:
I set a program to automatically load values from a temporary file. However, there is a chance that the specific temporary file "C:\Temp\TU.tmp" may not exist at all. In that case I want that...
2
by: gn | last post by:
I am a VB.Net newbie and have tried to search for this answer without success - What is the exact syntax to test if HttpContext.Current.Application("var") exists in vb.net I have tried: If...
1
by: Rajeshwar_ts | last post by:
Hi, I am new to this group and new to PostGreSql. i am changing from MySql to PostGresql. I am unable to work with "Drop table if exists tablename" query. Is there any alternate query for...
2
MatthewML
by: MatthewML | last post by:
I am attempting to insert a custom AfterUpdate Event Procedure into a text box on a form that I am designing in MS Access 2000. This text box contains the e-mail address of the referenced contact,...
3
by: nickvans | last post by:
Hello all, I have (hopefully) an easy question for you all. I'm running Access '03 and have created a pile of VBA code to create a form and some queries related to each control in the form....
3
by: Yansky | last post by:
If I have the following code: var abc; if(!abc){ alert('test'); }
7
by: itsraghz | last post by:
Hello All, I remember in MySQL we do have "IF EXISTS", 'IF NOT EXISTS" clause/keyword in the DDL statements (CREATE,DROP etc.,) to avoid unnecessary bombing. Do we have such facility in...
9
by: erictheone | last post by:
Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.