Ok... I have a terrible way of making this work
The goal is to take a prospect object
and store it in a MySQL database.Is there a better way?

sub InsertProspect { # Get the new prospect my $prospect = shift; # Connect to the database my $dbh = DBI->connect('DBI:mysql:menagerie', 'menagerie') or die +"Couldn't connect to database: " . DBI->errstr; # Set all of the variables that we need to pass to MySQL my $name = $prospect->name; my $address = $prospect->address; my $address2 = $prospect->address2; my $state = $prospect->state; my $city = $prospect->city; my $phone = $prospect->phone; my $phone2 = $prospect->phone2; my $phone3 = $prospect->phone3; my $phone4 = $prospect->phone4; my $phoneType = $prospect->phone; my $phone2Type = $prospect->phone2; my $phone3Type = $prospect->phone3; my $phone4Type = $prospect->phone4; my $email = $prospect->email; my $url = $prospect->url; my $interestLevel = $prospect->interestLevel; my $designFirm = $prospect->designFirm; my $hostingFirm = $prospect->hostingFirm; my $companyName = $prospect->companyName; # Insert the new prospect in the database my $sth = $dbh->prepare("INSERT INTO prospect VALUES (NULL, \"$nam +e\", \"$address\", \"$address2\", \"$state\", \"$city\", \"$phone\", +\"$phone2\", \"$phone3\", \"$phone4\", \"$phoneType\", \"$phone2Type\ +", \"$phone3Typ +e\", \"$phone4Type\", \"$email\", \"$url\", \"$interestLevel\", \"$de +signFirm\", \"$hostingFi +rm\", \"$companyName\")"); # Execute the statement $sth->execute or die print DBI->errstr; # Lets get the prospect id that we just added back $sth = $dbh->prepare("SELECT last_insert_id() from prospect"); $sth->execute or die print DBI->errstr; my @id = $sth->fetchrow_array; my $ID = $id[[0]]; # Return the new prospects ID return $ID; } I want to be good... really I do. I just don't know how :-)<p>
-- rogueFalcon

Why do you people insist on doing things sdrawkcab?

Edit by tye


In reply to MySQL / DBI / OOP by rogueFalcon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.