http://qs321.pair.com?node_id=994480


in reply to Deleting all from all tables in MYSQL

Howdy!

You can't use placeholders that way. MySQL can't parse a statement like "delete from ?", so you can't prepare it. You are pretty much stuck with "delete from $row[0]".

yours,
Michael
  • Comment on Re: Deleting all from all tables in MYSQL

Replies are listed 'Best First'.
Re^2: Deleting all from all tables in MYSQL
by justin423 (Scribe) on Sep 19, 2012 at 17:12 UTC
    Thanks. So would this work instead?
    my $query = $dbh->prepare('SHOW TABLES'); if (defined($query)) { $query->execute(); my @row; while (@row = $query->fetchrow_array()) { $sql = qq|delete from $row[0]|; $sth = $dbh->prepare($sql) or die "Cannot prepare: " . $dbh->errstr(); $sth->execute() or die "" . $sth->errstr();