IF EXISTS in MySQL 4.0x???

 
Post new topic   Reply to topic    Aprelium Forum Index -> Databases
View previous topic :: View next topic  
Author Message
MasterMan194
-


Joined: 16 Mar 2007
Posts: 2

PostPosted: Fri Mar 16, 2007 3:34 am    Post subject: IF EXISTS in MySQL 4.0x??? Reply with quote

Hi,
I'm now fidling with databases. Instaled the trio MySQL 4.0.24. PHPMyAdmin 2.8.0.3 and PHP 4.4.6, everything with Abyss X1 v2.4.
But i get an error when i do:
Code:
IF(EXISTS (SELECT * FROM examples WHERE name='".$name."')
 PRINT '".$name." exists'
 ELSE PRINT '".$name." does''t exists')") or die(mysql_error());

The error says "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS (SELECT *...".
So i'm thinking MySQL 4.0.24 can't do IF statements or EXISTS statements like this.
Then how can i procede? Upgrade to PHP 5 + MySQL 5?

Any ideas?

Thanks.
Back to top View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Fri Mar 16, 2007 8:40 am    Post subject: Reply with quote

Quote:
IF(EXISTS (SELECT * FROM examples WHERE name='".$name."')


missing ")" on the end. It should be

Quote:
IF(EXISTS (SELECT * FROM examples WHERE name='".$name."'))


Try that.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Sat Mar 17, 2007 4:01 am    Post subject: Reply with quote

It looks as if your SQL query is mixed with PHP code. That's invalid syntax.

You have to make your SQL query, assigning its response to a PHP variable. Then you have to make the data available to print in your PHP script (by using a fetch array command). Then you can print the data from that array.

You might try reading the tutorial at http://www.tizag.com/mysqlTutorial/
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
MasterMan194
-


Joined: 16 Mar 2007
Posts: 2

PostPosted: Sat Mar 17, 2007 4:48 am    Post subject: Reply with quote

Sorry, confused it with PHP code.

Look:
Code:

mysql> SELECT * FROM example WHERE age=25;
+----+------------+------+
| id | name       | age  |
+----+------------+------+
|  1 | joao vitor |   25 |
+----+------------+------+
1 row in set (0.01 sec)
mysql>

It works, but...

Code:

mysql> IF EXISTS ( SELECT * FROM example WHERE age=25 )
    -> PRINT 'age exists'
    -> ELSE
    -> PRINT 'age doesnt exists';
ERROR 1064: You have an error in your SQL syntax.  Check the manual that corresp
onds to your MySQL server version for the right syntax to use near 'IF EXISTS (
SELECT * FROM example WHERE age=25 )
PRINT 'age exi
mysql>

It doesn't.

Now that's command line in windows xp.

The documentation only talks about [IF EXISTS] in various DROP commands, not SELECT or INSERT or anything else :(
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Databases All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group