How to know if an insert was made in Mysql database

1

I need to create a webservice in which I can verify in a Mysql database if a new record is added to a table. This in order to call the webservice in a thread as an android service so that when a new record is added send a notification.

What happens is that I will not be the one to do the insert, it will be a script which will feed a database of another. what occurs to me is to count the rows of the table and store them in android studio can be in the preferences or a variable and when it is greater the new number of rows send notification I do not know how viable this is?

and how could I do to bring the number of rows in PDO?

    
asked by ALEX MAURICIO CADAVID QUICENO 15.09.2017 в 16:02
source

1 answer

1

You could do a row count after the insertion, or if you want something more advanced, linked with if the statement has been executed successfully, you can use this in PDO:

$statement = $pdo->prepare("INSERT INTO users ... ? ? ? ");
$statement->execute($data);

if( $statement ) return "Su registro ha sido insertado con éxito";

Because if the $stmt is executed correctly, it returns true .

    
answered by 15.09.2017 в 16:10