PDA

View Full Version : Perl test script to create tables


prp
4-18-03, 03:23 PM
Hello,

Is there a simple Perl script for making tables that I can use to test my installation and configuration? If there is, please send the code with instructions and expected results.

I'm assuming (not sure) that DBI and drivers are already installed in ns3.powweb.com for mysql02.powweb.com and the script should be set to chmod 755.

Thanks,
prp

netaustin
4-19-03, 03:27 AM
you assume correctly. both DBI and the mysql driver are installed on all powweb webservers. however, you'd be using the script on your webserver, not a nameserver or a dbserver. webservers provide the link between the data source (mysql02 in this case) and the end user.

if you want to perform diagnostics or operations of any sort on your database, i suggest mysql front or phpMyAdmin.

try this:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

use DBI;
$db="yourdatabase";
$host="mysql02.powweb.com";
$port="3306";
$user="username";
$pass="password";
$info="DBI:mysql:database=$db;$host:$port";

$dbh = DBI->connect($info,$user,$pass);

$query = "create table tablename (fieldname datatype(value), fieldname datatype(value))";

$sth = $dbh->prepare($query);
if $sth->execute() print "<br>It worked</br>";
$sth->finish();

$dbh->disconnect;

you need to edit this to reflect your database settings and the table you want to creat with its types and default values.