Count How Many Rows Inserted From Last SQL Query

前端 未结 2 1486
一个人的身影
一个人的身影 2021-01-18 02:12

I have this query :

INSERT INTO db1.outbox (DestinationNumber, TextDecoded)
SELECT User.CellPhone, \'$SMSMessage\' as TextDecoded
FROM db2.User
WHERE User.Pu         


        
2条回答
  •  独厮守ぢ
    2021-01-18 02:56

    Here are some possibilities:

    » If you have an AUTO_INCREMENT column, you can fetch the row number before and after insert

    » SELECT ROW_COUNT() returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE, DELETE, or INSERT (doc)

    » You can use mysqli_affected_rows (since mysql_ functions are being deprecated) to get the number of affected rows in a previous MySQL operation (doc)

    $link = mysqli_connect("localhost", "my_user", "my_password", "world");
    
    if (!$link) {
        printf("Can't connect to localhost. Error: %s\n", mysqli_connect_error());
        exit();
    }
    
    /* Insert rows */
    mysqli_query($link, "INSERT INTO myTable VALUES (1)");
    printf("Affected rows (INSERT): %d\n", mysqli_affected_rows($link));
    

提交回复
热议问题