SPUG: Creating tables on MySql
Brian Hatch
bri at ifokr.org
Mon Feb 9 12:56:12 CST 2004
> On Mon, Feb 09, 2004 at 10:27:02AM -0800, Luis Medrano wrote:
> > List,
> >
> > I have a question. I need to verify the existence of tables in MySql using perl and in case that table doesn't exist I need to created using perl of course. Any idea how can I do this??
> >
>
> Use Perl DBI
>
> http://dbi.perl.org/
Something ala
my $sth = $dbi->prepare("desc %");
my $success = $sth->execute();
if ( ! $success ) {
$sth = $dbi->prepare("create table blahblahblahblah");
$success = $sth->execute();
if ( ! $success ) {
die "Shoot, it didn't work."
}
}
MySQL can check for existance using 'desc' (to 'describe') though you
could of course do a 'select *' but that'd be overkill. 'select * limit 1'
might be a portable solution that misuse kill the server if it's a huge
table.
--
Brian Hatch Error 23 occured when
Systems and attempting to report
Security Engineer error 23.
http://www.ifokr.org/bri/
Every message PGP signed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.pm.org/pipermail/spug-list/attachments/20040209/c3551cb0/attachment.bin
More information about the spug-list
mailing list