• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

INSERT IGNORE SQL STATEMENT mysql php

When using a statement like INSERT IGNORE INTO table VALUES ('1','2','3') in php

How can I determine if the record was inserted or ignored?

for instance when I want to know if a sql statement executed correctly I would use something like

if ($sql) {
echo "ok";
} else {
echo "Not ok";
}

but since the sql statement executes correctly whether it is skipped or ignored how can I differentiate the two?

0
cbielich
Asked:
cbielich
2 Solutions
 
nkraynevCommented:
you can use mysql_affected_rows() function. It would return >0 if any records inserted

PS btw, you can change rows if they ignored:
insert ignore into ..... ON DUPLICATE KEY UPDATE name="value",name2="value2"...
0
 
Ray PaseurCommented:
See the man page here:
http://us.php.net/manual/en/function.mysql-affected-rows.php

Note what happens if the count is zero, one or more, or (drum roll) negative one!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now