Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > %Ultra Newbie Question% -- Perl & MYSQL working together

Reply
Thread Tools

%Ultra Newbie Question% -- Perl & MYSQL working together

 
 
Julia Briggs
Guest
Posts: n/a
 
      01-18-2004
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();
 
Reply With Quote
 
 
 
 
Gregory Toomey
Guest
Posts: n/a
 
      01-18-2004
Julia Briggs wrote:

> $stmt = "INSERT INTO wslookup (test_record)
> VALUES (‘testing')";


Do you mean‘'testing'

gtoomey
 
Reply With Quote
 
 
 
 
gnari
Guest
Posts: n/a
 
      01-18-2004
"Julia Briggs" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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.


this does not tell us much does it?
what id you do ?
what happened?
what did you expect to happen?
what did you try to do to fix it?

there are many things obviously wrong here, and some that might be.

> #!/usr/local/bin/perl


add here these lines:
use strict;
use warnings;

> # Use the DBI module
> use DBI qw(:sql_types);


do you get an error message saying something DBI something?

> my ($databaseName, $databaseUser, $databasePw, $dbh);
> my ($stmt, sth, @newRow);


the sth should be $sth. did you get an error message mentioning
this line?

> my ($test_record);
>
> # Set the parameter values for the connection
> $databaseName = "dbname";
> $databaseUser = "user";
> $databasePw = "password";


did you replace these with actual real-world values?
does the database and user exist?

>
> $dbh = DBI->connect($databaseName, $databaseUser,
> $databasePw) || die "Connect failed: $DBI::errstr\n";


something is missing here. $dbh is not defined.
did you get an error message about that, or did you just
skip a part in your posting?

>
> # Create the statement.
> $stmt = "INSERT INTO wslookup (test_record)
> VALUES ('testing')";


does a table 'wslookup' exist with column 'test_record'?

>
> # Prepare and execute the SQL query
> $sth = $$dbh->prepare($$stmt)
> || die "prepare: $$stmt: $DBI::errstr";
> $sth->execute || die "execute: $$stmt: $DBI::errstr";


whats the deal with the double $ chars?

>
> # Clean up the record set and the database connection
> $sth->finish();
> $dbh->disconnect();



hope this helps.
gnari




 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      01-18-2004
Julia Briggs <(E-Mail Removed)> wrote:

> Can someone look at this and fix, or post
> a simple example of how this should work?



We could if we weren't conditioned crickets jumping all over the place.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Julia Briggs
Guest
Posts: n/a
 
      01-19-2004
> We could if we weren't conditioned crickets jumping all over the place.

Add to "some" of the "we" as you globally indicate, who are hostile --
and also quite predictable... You might do better next time if you
just shut up or you'll just continue imagining using your words that
you somehow speak for 100% of the people in this newsgroup.
 
Reply With Quote
 
Peter Hickman
Guest
Posts: n/a
 
      01-19-2004
Julia Briggs wrote:
> # Set the parameter values for the connection
> $databaseName = "dbname";


Is this an example or are you actually using "dbname". It is usually of the
type "mysql:database=wizdom", that is the type of database (MySQL, PostgreSQL
etc) followed by the name of the actual database.

> $databaseUser = "user";
> $databasePw = "password";
>
> $dbh = DBI->connect($databaseName, $databaseUser,
> $databasePw) || die "Connect failed: $DBI::errstr\n";


Did you get an error at this point?

> # 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";


Or did you get an error here?

> $sth->execute || die "execute: $$stmt: $DBI::errstr";


Or perhaps here?

>
> # Clean up the record set and the database connection
> $sth->finish();
> $dbh->disconnect();


Or did it run through to the end?

Has the wslookup table been created, what is it's structure?

The code is usefull but unless we have the exact same setup as yourself (and
you didn't tell us what that was) then the problems we have getting it to run
will not neccessarily be the same as yours.

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      01-19-2004
[attribute your quotations properly]

(E-Mail Removed) (Julia Briggs) wrote:
>
> Tad wrote:
> >
> > We could if we weren't conditioned crickets jumping all over the place.

>
> you somehow speak for 100% of the people in this newsgroup.


s/(?<=people) (?=in)/ with a clue /;

Ben

--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: getting perl and C working together in a way that makes sense Johann Klammer C Programming 0 02-01-2013 08:30 AM
Ultra Products Ultra Fire Silverstrand Front Page News 1 06-29-2005 12:29 PM
ihug ultra speed test - ne1 with ultra wanna try this test for me? cowboyz NZ Computing 14 11-25-2004 10:29 PM
Sandisk Ultra II, "new" Ultra, "original " Ultra Eberhard Funke Digital Photography 0 01-13-2004 04:35 PM
Ultra ATA/100 HDD on a Ultra ATA/33 motherboard Prinxce of Darkxness Computer Support 3 01-06-2004 05:36 PM



Advertisments