Newbie-Prob2

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Thanatos
Forum Newbie
Posts: 3
Joined: Thu Jul 04, 2002 8:19 am
Contact:

Newbie-Prob2

Post by Thanatos »

My second prob is that I have to check whether a set already exists or not, and then do an update or an insert.

How can I realize this?

Greets
Thanatos
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

use mysql_affected_rows to see wether data has been altered or not.

Code: Select all

mysql_query($sqlUpdate, $conn) or die(mysql_error());
if (mysql_affected_rows($conn)==0)
   // *)
   mysql_query($sqlInsert, $conn) or die(mysql_error());
*) mysql_affected_rows also returns 0 if the data is exactly the same as before. If these kinds of updates are possible you must do a 'select...' in the if-clause to check wether there are such records or not
Post Reply