Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //take an update or delete MySQL query and generate a query that gets a count of the rows that will be affected by the query, prints that number, then runs the original update/delete query
- function run_query($query){
- $query = "update Users set Name = 'foobar' where ID = 1";
- //$query = "delete from Users where ID = 1;
- $cnt_query = preg_replace('/^(update|delete)\s(from\s)?(\w+)[\w\s\=\'\,]+(where.*)$/i', 'select count(*) as cnt from $3 $4', $query);
- $cnt_line = mysql_fetch_assoc(mysql_query($cnt_query));
- echo $cnt_line['cnt'] . "\n";
- mysql_query($query);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement