Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Deleting all from all tables in MYSQL

by herveus (Parson)
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 (Acolyte) 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
Node Status?
node history
Node Type: note [id://994480]
help
Chatterbox?
[marto]: hmm, may have to patch CPAN::Meta to move from search.cpan to metacpan in the META.json/yml files
[Corion]: marto: Heh - it seems that they plan to keep the search.cpan.org links alive for a long time. But still, I plan on moving PM to use/generate the new links
[Corion]: And I think it's better to generate links to the new world instead of keeping the older links alive by generating new versions of them ;)
[marto]: yeah, I guess it's supposed to be a permanent redirect, but better to make the move where possible

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2018-05-23 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?