I started to learn MySQL a few months back but got back tracked but now I'm ready to give it another try.

Can someone assist me with the logic of how to go about setting this up? I'm converting my link tracker over to a MySQL backend to make the data more sortable.

What it's doing here is checking a url_param for the referring URL and checking whether or not it was in the id row already. If it wasn't, it'll setup the current data (the ip address, the time it was clicked and will start with 1 view).

If the url was already setup, it will autoincrement "views", store the current IP address in last_ip (overwriting original value) and store it with ALL ips in all_ip.

I'm to the point where I bind the variables to the columns but from here I don't know what to do.

Any assistance would be much appreciated.

###### # Connecting to our database ###### my $dbh = DBI->connect("DBI:mysql:$dbase", $mysql_user, $mysql_pass) o +r print DBI=>"errstr"; my $url = url_param("url"); ###### # Was the referring URL in the database? or not ###### my $data = qq(SELECT id, views, last_ip, last_time, all_ip FROM track +where id = "$url"); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; if ($sth->rows < 1) { my ($id, $views, $last_ip, $last_time, $all_ip); $sth->bind_columns(\$id, \$views, \$last_ip, \$last_time, \$all_ip) +; # nothing was here so we'll setup the values starting with 1 view } else { my ($id, $views, $last_ip, $last_time, $all_ip); $sth->bind_columns(\$id, \$views, \$last_ip, \$last_time, \$all_ip) +; # this URL was tracked previously, we have to autoincrement $views +and store all our info }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

In reply to MySQL logic by sulfericacid

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.