View previous topic :: View next topic |
Author |
Message |
MasterMan194 -
Joined: 16 Mar 2007 Posts: 2
|
Posted: Fri Mar 16, 2007 3:34 am Post subject: IF EXISTS in MySQL 4.0x??? |
|
|
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 |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Fri Mar 16, 2007 8:40 am Post subject: |
|
|
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 |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Sat Mar 17, 2007 4:01 am Post subject: |
|
|
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 |
|
|
MasterMan194 -
Joined: 16 Mar 2007 Posts: 2
|
Posted: Sat Mar 17, 2007 4:48 am Post subject: |
|
|
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 |
|
|
|