J
Julia Briggs
I am very new at this, and looking for a very simple standalone script
to insert data into a mysql database. I found this posted somewhere
else, but can't seem to get it to execute. It probably has the wrong
values - or something else. Can someone look at this and fix, or post
a simple example of how this should work? Thank you so much!
)
Sincerely,
Julia Briggs
#!/usr/local/bin/perl
# Use the DBI module
use DBI qw
sql_types);
# Declare local variables
my ($databaseName, $databaseUser, $databasePw, $dbh);
my ($stmt, sth, @newRow);
my ($test_record);
# Set the parameter values for the connection
$databaseName = "dbname";
$databaseUser = "user";
$databasePw = "password";
$dbh = DBI->connect($databaseName, $databaseUser,
$databasePw) || die "Connect failed: $DBI::errstr\n";
# Create the statement.
$stmt = "INSERT INTO wslookup (test_record)
VALUES (‘testing')";
# Prepare and execute the SQL query
$sth = $$dbh->prepare($$stmt)
|| die "prepare: $$stmt: $DBI::errstr";
$sth->execute || die "execute: $$stmt: $DBI::errstr";
# Clean up the record set and the database connection
$sth->finish();
$dbh->disconnect();
to insert data into a mysql database. I found this posted somewhere
else, but can't seem to get it to execute. It probably has the wrong
values - or something else. Can someone look at this and fix, or post
a simple example of how this should work? Thank you so much!
Sincerely,
Julia Briggs
#!/usr/local/bin/perl
# Use the DBI module
use DBI qw
# Declare local variables
my ($databaseName, $databaseUser, $databasePw, $dbh);
my ($stmt, sth, @newRow);
my ($test_record);
# Set the parameter values for the connection
$databaseName = "dbname";
$databaseUser = "user";
$databasePw = "password";
$dbh = DBI->connect($databaseName, $databaseUser,
$databasePw) || die "Connect failed: $DBI::errstr\n";
# Create the statement.
$stmt = "INSERT INTO wslookup (test_record)
VALUES (‘testing')";
# Prepare and execute the SQL query
$sth = $$dbh->prepare($$stmt)
|| die "prepare: $$stmt: $DBI::errstr";
$sth->execute || die "execute: $$stmt: $DBI::errstr";
# Clean up the record set and the database connection
$sth->finish();
$dbh->disconnect();