473,856 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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", "lkjlkjlkjl jk")
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 11128
*** 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", "lkjlkjlkjl jk")
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_definit ion,...)]
[table_options] [select_statemen t]
"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_tabl es() 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", "lkjlkjlkjl jk")

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("i nsert something into my table values etc");

Jul 17 '05 #3
In article <41************ ***@nospamun8no spam.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", "lkjlkjlkjl jk")

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("i nsert 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", "lkjlkjlkjl jk")


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_definit ion,...)]
[table_options] [select_statemen t]


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_tabl es() 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
4404
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, the "while" portion of a recordset. The best way I can ask is show what I mean. http://oscarguy.mechphisto.net/awardbrowse.php If you go there and select an award (like Best Picture), leave the year field alone, and select YES and submit,...
5
6698
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 specific routine to be skipped. I guess this is a simple If (that file exists) Open "C:\Temp\TU.tmp" For Input As #3 etc....... Else GoTo
2
5317
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 (HttpContext.Current.Application("var").ToString) <> "" Then That gives me System.NullReferenceException: Object reference not set to an instance of an object Error, I suspect because I am trying to
1
11534
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 that?? Please help me
2
11957
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, and my goal is to automatically insert the "@abc.xyz" portion of the e-mail data string if and only if the user does not specify this part of the data string. I am attempting to do this because 99% of the e-mail addresses that I will be entering into...
3
32141
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. (Basically, it uses structured naming conventions to create a form with a bunch of combo boxes that allow the user to easily add and remove controls... anyway--) I am using the statement With CurrentDb .QueryDefs.Delete ("qryName") Set qrydef =...
3
2026
by: Yansky | last post by:
If I have the following code: var abc; if(!abc){ alert('test'); }
7
59268
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 Oracle? If not is there any other easy way to achieve it? I am using Oracle 10g. I have been searching through google and also in oracle.com but unable to get it out. Thanks, Raghavan alias Saravanan M.
9
27649
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 patterns(words). What it does is takes a string as a parameter, determines length of string, tests if the length is a perfect square, if it is then it makes a 2-d array with its length and height equal to the lengths root. If it isn't then it cuts it down to...
0
11056
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10696
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10782
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10384
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7932
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7093
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5761
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3201
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.