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

Discussion in 'Perl Misc' started by Julia Briggs, Jan 18, 2004.

  1. Julia Briggs

    Julia Briggs Guest

    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();
     
    Julia Briggs, Jan 18, 2004
    #1
    1. Advertising

  2. Julia Briggs wrote:

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


    Do you mean‘'testing'

    gtoomey
     
    Gregory Toomey, Jan 18, 2004
    #2
    1. Advertising

  3. Julia Briggs

    gnari Guest

    "Julia Briggs" <> wrote in message
    news:...
    > 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
     
    gnari, Jan 18, 2004
    #3
  4. Julia Briggs <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 18, 2004
    #4
  5. Julia Briggs

    Julia Briggs Guest

    > 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.
     
    Julia Briggs, Jan 19, 2004
    #5
  6. 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.
     
    Peter Hickman, Jan 19, 2004
    #6
  7. Julia Briggs

    Ben Morrow Guest

    [attribute your quotations properly]

    (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/' #
     
    Ben Morrow, Jan 19, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Julia Briggs

    * Ultra Newbie HTML Question *

    Julia Briggs, Nov 29, 2003, in forum: HTML
    Replies:
    2
    Views:
    382
    Spartanicus
    Nov 29, 2003
  2. John Salerno

    ultra newbie question (don't laugh)

    John Salerno, Sep 26, 2006, in forum: Python
    Replies:
    7
    Views:
    287
    Peter Otten
    Sep 26, 2006
  3. Tayna Taylor

    % Ultra Newbie Question %

    Tayna Taylor, Nov 29, 2003, in forum: Javascript
    Replies:
    3
    Views:
    132
    Tayna Taylor
    Nov 30, 2003
  4. Tayna Taylor
    Replies:
    1
    Views:
    115
  5. Leodiensian
    Replies:
    0
    Views:
    86
    Leodiensian
    Apr 15, 2004
Loading...

Share This Page