Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Deleting all from all tables in MYSQL

by herveus (Prior)
on Sep 19, 2012 at 17:00 UTC ( #994480=note: print w/replies, xml ) Need Help??


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 (Beadle) 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();

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://994480]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2023-09-25 14:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?