From: Curt Zirzow [EMAIL PROTECTED]
I should instead just try to perform the INSERT and then if it fails I
know I've already got a record. If it doesn't I know everything is cool.
I've debated with myself several times if this is really a good
method to not have duplicates in the database.
Hi!
(MySQL)
What's the best way to determine a sql INSERT statement has executed
successfully?
What I've got is a function whose sole purpose is to add new staff
members to an app. I've written. There's a basic form that the user
fills out (first name, last name, email address) and submits.
Chris W. Parker wrote:
Hi!
(MySQL)
What's the best way to determine a sql INSERT statement has executed
successfully?
You should use mysql_error() to ensure your query did not fail for any
reason. Assuming the query was successful, you can use
mysql_affected_rows() to see if it actually had
mysql_query() will return true for queries that don't return rows and
were executed without error, so you can use
return mysql_query();
You should also make a UNIQUE index on email column, then you can check
the number returned by mysql_errno(), one number I don't remember
signals duplicate
John W. Holmes mailto:[EMAIL PROTECTED]
on Monday, August 25, 2003 5:37 PM said:
You should use mysql_error() to ensure your query did not fail for any
reason. Assuming the query was successful, you can use
mysql_affected_rows() to see if it actually had any impact on the
database, i.e.
Marek Kilimajer mailto:[EMAIL PROTECTED]
on Tuesday, August 26, 2003 3:59 AM said:
mysql_query() will return true for queries that don't return rows and
were executed without error, so you can use
return mysql_query();
You should also make a UNIQUE index on email column, then you can
From: Chris W. Parker [EMAIL PROTECTED]
I should instead just try to perform the INSERT and then if it fails I
know I've already got a record. If it doesn't I know everything is cool.
If it is a certain kind of failure, then you have a duplicate, otherwise it
could be another type of
* Thus wrote Chris W. Parker ([EMAIL PROTECTED]):
Marek Kilimajer mailto:[EMAIL PROTECTED]
on Tuesday, August 26, 2003 3:59 AM said:
mysql_query() will return true for queries that don't return rows and
were executed without error, so you can use
return mysql_query();
You should
Curt Zirzow mailto:[EMAIL PROTECTED]
on Tuesday, August 26, 2003 11:26 AM said:
Like what happens if for some reason the constraint gets dropped?
having your progam rely on the constraint will cause all data
integrity to go to hell.
In that case I hope you're also incrementing your own
9 matches
Mail list logo