Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: MySQL avoid multiple connect request

by poj (Abbot)
on May 23, 2014 at 10:20 UTC ( [id://1087185]=note: print w/replies, xml ) Need Help??


in reply to MySQL avoid multiple connect request

USE database should work with MySQL ;
#!/usr/bin/perl use strict; use warnings; use DBI; my $db = 'xxxx'; my $table = 'xxxx'; my $dbh = dbh(); # connect # create database $dbh->do('CREATE DATABASE IF NOT EXISTS '.$db) or die "Could not create database $db : ". $dbh->errstr; # create table $dbh->do("USE $db"); $dbh->do("CREATE TABLE IF NOT EXISTS $table ( id int(11) NOT NULL AUTO_INCREMENT, UnixTime int(11) NOT NULL, losses int(11) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1"); # insert data my $range = 50; my $minimum = 100; my $random_number = int(rand($range)) + $minimum; my $time = time(); $dbh->do("INSERT IGNORE INTO $table (UnixTime,losses) VALUES (?,?)", undef, $time,$random_number); print "added $time $random_number to $db table $table\n"; sub dbh { my $dsn = "DBI:mysql:database=;host=localhost"; my $dbh = DBI->connect($dsn, 'user', 'pwd', {RaiseError => 1, PrintError => 1}) or die (Error connecting " $DBI::errstr"); }
poj

Replies are listed 'Best First'.
Re^2: MySQL avoid multiple connect request
by thanos1983 (Parson) on May 23, 2014 at 21:08 UTC

    To poj:

    Exactly what I need, so simple yet I could not find it online. To be honest I did not think even testing for my self, I thought that since I can not find it, it is not possible.

    Again thanks for your time and effort assisting me to my problem.

    Seeking for Perl wisdom...on the process...not there...yet!

      I thought that since I can not find it, it is not possible.
      That's the mentality you want to avoid! Simply make a backup(easy as copying the table) of both database and code, then try it.
      The worst thing that can happen is that you have to restore the data(unless you're so dense as to do it on a production server etc).

      ~Thomas~ 
      "Excuse me for butting in, but I'm interrupt-driven..."

        Recently seen on a T-shirt worn by a sysadmin at $work: "I don't always test my code, but when I do I prefer to do it on production."

        The sad part, most of us think the person in question actually felt that way.

        It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

        To: Thomas,

        This is a true story, it would be extremely easy to try it and test it even if I could not find it. I think I should embrace the courage to first try multiple attempts before applying. Thank you for your time and effort.

        Seeking for Perl wisdom...on the process...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1087185]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-23 06:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found