Posted on 2009-12-29
Last Modified: 2013-12-12
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?

Question by:cbielich
    LVL 3

    Assisted Solution

    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"...
    LVL 107

    Accepted Solution

    See the man page here:

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

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now